ALTER TABLE tm_TraRemCum ADD tmCdCCosto VARCHAR(16),tmCdSubCos VARCHAR(16)
GO
ALTER TABLE Trn_TraCumRemesas ADD CodCCosto VARCHAR(16),CodSubCos VARCHAR(16)
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_TraRemCum]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_TraRemCum]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_TraRemCum_Muc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_TraRemCum_Muc]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_TraRemCum_Sel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_TraRemCum_Sel]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInstm_TraRemCum_Trr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInstm_TraRemCum_Trr]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTraCumRemesas]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTraCumRemesas]
GO

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)
SELECT @pmtmNumero,D.Item,TipRem,Remesa,IdCiaRem,ItemRem,IdMercancia,DescripMcias,Cantidad,PesoNeto,UndMed,Volumen,UndVol,Cases,Cajas,Palets,R.TarifClie,R.TarifPago,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,'',''
 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
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)
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,'',''
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
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)
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
 FROM Trn_TraCumRemesas 
 WHERE TipDoc=@pmTipDoc AND Cumplido=@pmCumplido AND IdCia=@pmIdCia
GO
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)
 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)
 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)
GO
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)
 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)
 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)
GO
