INSERT INTO adm_Opciones (IdOpc,Opcion,TipoDato,Valor,NivUp,nModulo)
 VALUES ('ANC','ACTUALIZAR INFORMACION DE NOMINA EN CREACION DE CONDUCTORES','BOOLEAN','0',5,'TRANS')
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_ResMensualCueN]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQrytm_ResMensualCueN]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQrytm_ResMensualCue]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQrytm_ResMensualCue]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTraRemMciasMuc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTraRemMciasMuc]
GO

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
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
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=@pmTarifPago,TarifTabla=@pmTarifTabla,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
