Cambios a sp y creación de spGetMorosidadPorProvincia
Aproximadamente 5 horas
Se hicieron cambios a los stored procedures get detalle recibo, ya que no complía con todas las consultas que venían en el requerimiento, támbien se cambió el procedimiento hacer pago, ya que debía cumplir conque era el mismo procedimiento que se corria a la hora de simular los pagos masivos y simular un pago de un recíbo, esto llevó una hora y media ya que hubo que consultar con el profesor algunas dudas sobre la especificación, además se creó el sp GetMorosidadPorProvincia, este llevó más tiempo ya que a como está implementado hay una complicación con el secuencial, ya que al ser un identity de una tabla temporal no se puede reiniciar a 0 por lo que hubo que ingresar los datos sin borrar e iterar por los que se habían ingresado de último, este es el código sin contemplar lo del identity secuencial:
CREATE PROCEDURE [dbo].[spGetMorosidadPorProvincia]
as
begin
Declare @codigoPostal int = (Select CodigoPostal from Propiedad where ID = 1)
Declare @Municipalidades table (ID int, nombre nvarchar(20))
Declare @resultado table (ID int, Provincia nvarchar(20), sumatoriaMorosidad float)
Declare @tablaPropiedadesDeMunicipalidad table (sec int identity(1,1), idMuni int, numFinca int)
Declare @detalleXPropiedad table (sec int identity(1,1), secSp int, numeroAbonado int, documentoIdentificacion int, nombreAbonado nvarchar(20), fechaEmision datetime, fechaLimite datetime, montoAgua float, montoAlumbrado float, montoBasura float, montoParques float, montoPatente float, intMoratorio float, subTotal float)
Declare @recibosXpropiedad table (sec int identity(1,1), idRecibo int, numFinca int)
Declare @propiedades table (ID int, numFinca int, codigoPostal int)
Insert into @Municipalidades Select ID,Nombre from Municipalidad
DECLARE @low int = 1
DECLARE @high int
DECLARE @lowProp int = 1
DECLARE @highProp int
DECLARE @lowRecibo int = 1
DECLARE @highRecibo int
DECLARE @sumatoriaMorosidadPorMuni float
DECLARE @idRecibotmp int
DECLARE @codigoPostalTmp int
Select @high = max(ID) from @Municipalidades
while @low < @high
begin
Delete from @tablaPropiedadesDeMunicipalidad where idMuni > 0
Insert into @tablaPropiedadesDeMunicipalidad Select IdMunicipalidad, NumeroFinca from Propiedad where IdMunicipalidad = @low
Set @sumatoriaMorosidadPorMuni = 0
Set @lowProp = 1
Select @highProp = max(sec) from @tablaPropiedadesDeMunicipalidad
while @lowProp < @highProp
begin
Delete from @recibosXpropiedad where sec > 0
Insert into @recibosXpropiedad Select ID, NumeroFinca from Recibo where ID = @lowProp
Set @lowRecibo = 1
Select @highRecibo = max(sec) from @recibosXpropiedad
while @lowRecibo < @highRecibo
begin
Set @idRecibotmp = (Select idRecibo from @recibosXpropiedad where sec = @lowRecibo)
Delete from @detalleXPropiedad where sec > 0
Insert into @detalleXPropiedad Exec spGetDetalleRecibo @idRecibo = @idRecibotmp
Set @sumatoriaMorosidadPorMuni = @sumatoriaMorosidadPorMuni + (Select intMoratorio from @detalleXPropiedad where sec = (Select MAX(sec) from @detalleXPropiedad))
Set @lowRecibo = @lowRecibo + 1
end
Set @lowProp = @lowProp + 1
end
Insert into @resultado values ((Select ID from @Municipalidades where ID = @low),(Select nombre from @Municipalidades where ID = @low),@sumatoriaMorosidadPorMuni)
print 'iteracion'
Set @sumatoriaMorosidadPorMuni = 0
Set @low = @low + 1
end
Select * from @resultado
end
Luego de analizar el sp se llegó a la conclusión de que el error era el secuencial, por lo que se implementó de la siguiente forma iterando sobre los nuevos elementos de la lista para así no repetir datos y arreglar lo del secuencial:
ALTER PROCEDURE [dbo].[spGetMorosidadPorProvincia]
as
begin
Declare @Municipalidades table (ID int, nombre nvarchar(20))
Declare @resultado table (ID int, Provincia nvarchar(20), sumatoriaMorosidad float)
Declare @tablaPropiedadesDeMunicipalidad table (sec int identity(1,1), idMuni int, numFinca int)
Declare @recibosXpropiedad table (sec int identity(1,1), idRecibo int, numFinca int)
Insert into @Municipalidades Select ID,Nombre from Municipalidad
DECLARE @low int = 1
DECLARE @high int
DECLARE @lowProp int = 1
DECLARE @highProp int
DECLARE @getProplow int = 1
DECLARE @getPropHigh int
DECLARE @sumatoriaMorosidadPorMuni float
DECLARE @numFincaTmp int
DECLARE @codigoPostalTmp int
DECLARE @resultadoByPropiedad float
Select @high = max(ID) from @Municipalidades
while @low <= @high
begin
Select @lowProp = MAX(sec) from @tablaPropiedadesDeMunicipalidad
if(@lowProp is null)
Set @lowProp = 1
Set @getProplow = 1
Select @getPropHigh = MAX(ID) from Propiedad
while @getProplow <= @getPropHigh
begin
if((Select codigoPostal from Propiedad where ID = @getProplow)/10000 = @low)
begin
Insert into @tablaPropiedadesDeMunicipalidad Select IdMunicipalidad, NumeroFinca from Propiedad where IdMunicipalidad = @low
end
Set @getProplow = @getProplow + 1
end
Set @sumatoriaMorosidadPorMuni = 0
Select @highProp = MAX(sec) from @tablaPropiedadesDeMunicipalidad
while @lowProp <= @highProp
begin
Set @numFincaTmp = (Select numFinca from @tablaPropiedadesDeMunicipalidad where sec = @lowProp)
Exec spGetSumaMorosidadFromPropiedad @numFinca = @numFincaTmp,@resultado = @resultadoByPropiedad output
Set @sumatoriaMorosidadPorMuni = @sumatoriaMorosidadPorMuni + @resultadoByPropiedad
Set @lowProp = @lowProp + 1
end
Insert into @resultado values ((Select ID from @Municipalidades where ID = @low),(Select nombre from @Municipalidades where ID = @low),@sumatoriaMorosidadPorMuni)
Set @sumatoriaMorosidadPorMuni = 0
Set @low = @low + 1
end
Select * from @resultado order by sumatoriaMorosidad desc
end
Se hicieron cambios a los stored procedures get detalle recibo, ya que no complía con todas las consultas que venían en el requerimiento, támbien se cambió el procedimiento hacer pago, ya que debía cumplir conque era el mismo procedimiento que se corria a la hora de simular los pagos masivos y simular un pago de un recíbo, esto llevó una hora y media ya que hubo que consultar con el profesor algunas dudas sobre la especificación, además se creó el sp GetMorosidadPorProvincia, este llevó más tiempo ya que a como está implementado hay una complicación con el secuencial, ya que al ser un identity de una tabla temporal no se puede reiniciar a 0 por lo que hubo que ingresar los datos sin borrar e iterar por los que se habían ingresado de último, este es el código sin contemplar lo del identity secuencial:
CREATE PROCEDURE [dbo].[spGetMorosidadPorProvincia]
as
begin
Declare @codigoPostal int = (Select CodigoPostal from Propiedad where ID = 1)
Declare @Municipalidades table (ID int, nombre nvarchar(20))
Declare @resultado table (ID int, Provincia nvarchar(20), sumatoriaMorosidad float)
Declare @tablaPropiedadesDeMunicipalidad table (sec int identity(1,1), idMuni int, numFinca int)
Declare @detalleXPropiedad table (sec int identity(1,1), secSp int, numeroAbonado int, documentoIdentificacion int, nombreAbonado nvarchar(20), fechaEmision datetime, fechaLimite datetime, montoAgua float, montoAlumbrado float, montoBasura float, montoParques float, montoPatente float, intMoratorio float, subTotal float)
Declare @recibosXpropiedad table (sec int identity(1,1), idRecibo int, numFinca int)
Declare @propiedades table (ID int, numFinca int, codigoPostal int)
Insert into @Municipalidades Select ID,Nombre from Municipalidad
DECLARE @low int = 1
DECLARE @high int
DECLARE @lowProp int = 1
DECLARE @highProp int
DECLARE @lowRecibo int = 1
DECLARE @highRecibo int
DECLARE @sumatoriaMorosidadPorMuni float
DECLARE @idRecibotmp int
DECLARE @codigoPostalTmp int
Select @high = max(ID) from @Municipalidades
while @low < @high
begin
Delete from @tablaPropiedadesDeMunicipalidad where idMuni > 0
Insert into @tablaPropiedadesDeMunicipalidad Select IdMunicipalidad, NumeroFinca from Propiedad where IdMunicipalidad = @low
Set @sumatoriaMorosidadPorMuni = 0
Set @lowProp = 1
Select @highProp = max(sec) from @tablaPropiedadesDeMunicipalidad
while @lowProp < @highProp
begin
Delete from @recibosXpropiedad where sec > 0
Insert into @recibosXpropiedad Select ID, NumeroFinca from Recibo where ID = @lowProp
Set @lowRecibo = 1
Select @highRecibo = max(sec) from @recibosXpropiedad
while @lowRecibo < @highRecibo
begin
Set @idRecibotmp = (Select idRecibo from @recibosXpropiedad where sec = @lowRecibo)
Delete from @detalleXPropiedad where sec > 0
Insert into @detalleXPropiedad Exec spGetDetalleRecibo @idRecibo = @idRecibotmp
Set @sumatoriaMorosidadPorMuni = @sumatoriaMorosidadPorMuni + (Select intMoratorio from @detalleXPropiedad where sec = (Select MAX(sec) from @detalleXPropiedad))
Set @lowRecibo = @lowRecibo + 1
end
Set @lowProp = @lowProp + 1
end
Insert into @resultado values ((Select ID from @Municipalidades where ID = @low),(Select nombre from @Municipalidades where ID = @low),@sumatoriaMorosidadPorMuni)
print 'iteracion'
Set @sumatoriaMorosidadPorMuni = 0
Set @low = @low + 1
end
Select * from @resultado
end
Luego de analizar el sp se llegó a la conclusión de que el error era el secuencial, por lo que se implementó de la siguiente forma iterando sobre los nuevos elementos de la lista para así no repetir datos y arreglar lo del secuencial:
ALTER PROCEDURE [dbo].[spGetMorosidadPorProvincia]
as
begin
Declare @Municipalidades table (ID int, nombre nvarchar(20))
Declare @resultado table (ID int, Provincia nvarchar(20), sumatoriaMorosidad float)
Declare @tablaPropiedadesDeMunicipalidad table (sec int identity(1,1), idMuni int, numFinca int)
Declare @recibosXpropiedad table (sec int identity(1,1), idRecibo int, numFinca int)
Insert into @Municipalidades Select ID,Nombre from Municipalidad
DECLARE @low int = 1
DECLARE @high int
DECLARE @lowProp int = 1
DECLARE @highProp int
DECLARE @getProplow int = 1
DECLARE @getPropHigh int
DECLARE @sumatoriaMorosidadPorMuni float
DECLARE @numFincaTmp int
DECLARE @codigoPostalTmp int
DECLARE @resultadoByPropiedad float
Select @high = max(ID) from @Municipalidades
while @low <= @high
begin
Select @lowProp = MAX(sec) from @tablaPropiedadesDeMunicipalidad
if(@lowProp is null)
Set @lowProp = 1
Set @getProplow = 1
Select @getPropHigh = MAX(ID) from Propiedad
while @getProplow <= @getPropHigh
begin
if((Select codigoPostal from Propiedad where ID = @getProplow)/10000 = @low)
begin
Insert into @tablaPropiedadesDeMunicipalidad Select IdMunicipalidad, NumeroFinca from Propiedad where IdMunicipalidad = @low
end
Set @getProplow = @getProplow + 1
end
Set @sumatoriaMorosidadPorMuni = 0
Select @highProp = MAX(sec) from @tablaPropiedadesDeMunicipalidad
while @lowProp <= @highProp
begin
Set @numFincaTmp = (Select numFinca from @tablaPropiedadesDeMunicipalidad where sec = @lowProp)
Exec spGetSumaMorosidadFromPropiedad @numFinca = @numFincaTmp,@resultado = @resultadoByPropiedad output
Set @sumatoriaMorosidadPorMuni = @sumatoriaMorosidadPorMuni + @resultadoByPropiedad
Set @lowProp = @lowProp + 1
end
Insert into @resultado values ((Select ID from @Municipalidades where ID = @low),(Select nombre from @Municipalidades where ID = @low),@sumatoriaMorosidadPorMuni)
Set @sumatoriaMorosidadPorMuni = 0
Set @low = @low + 1
end
Select * from @resultado order by sumatoriaMorosidad desc
end
Al final se procedió a montar todos los sp con la interfáz gráfica lo cuál tambien llevó vario tiempo ya que habían sp que en una base estában desactualizados y había que cambiarlos con cuidado para no perder los sp que eran la última versión y cumplían con todos los requisitos.
Comentarios
Publicar un comentario