ALTER TABLE Trn_DocSoporteDet ADD CodCC VARCHAR(16),CodSubCc VARCHAR(16)
GO
ALTER TABLE ProdMcias ADD TipoProdCo VARCHAR(10)
GO
ALTER TABLE Trn_OilMediciones  ADD VolPT DECIMAL(16,6) DEFAULT(0) NOT NULL,VolMP DECIMAL(16,6) DEFAULT(0) NOT NULL
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TiposProd](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[TipoProd] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TiposProd] PRIMARY KEY CLUSTERED ([Id])
)
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[TiposProd]  WITH CHECK ADD  CONSTRAINT [CK_TiposProdTipoProd] CHECK  ((len([TipoProd])>(0)))
GO
ALTER TABLE [dbo].[TiposProd] CHECK CONSTRAINT [CK_TiposProdTipoProd]

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsDocSoporteDet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsDocSoporteDet]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsProdMcias]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsProdMcias]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsProdMcias_Sel]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsProdMcias_Sel]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryProdMcias]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryProdMcias]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryProdMcias_Cr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryProdMcias_Cr]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryProdMciasLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryProdMciasLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpProdMcias]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpProdMcias]
GO

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,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
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
,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
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)
 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)
 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)
GO
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)
 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
 FROM  ProdMcias WHERE IdProducto=@pmIdProducto
GO
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),@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,FechaUpdate=@pmFechaUpdate
 WHERE IdProducto=@pmIdProducto
GO
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),@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)
 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)
GO
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,FechaAdd,FechaUpdate,IdUsuario
 FROM ProdMcias
 WHERE IdProducto=@pmIdProducto
GO
