Advertisement
LovelessIsma

pa_reporteRO

Jul 6th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 21.49 KB | None | 0 0
  1. USE [SNSMART_ANALISIS]
  2. GO
  3. /****** Object:  StoredProcedure [SN].[pa_reporteRO]    Script Date: 06/07/2016 0:28:47 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. ALTER procedure [SN].[pa_reporteRO] (
  10.     @mes int,
  11.     @anho int,
  12.     @tiporegistro int
  13. )
  14. AS
  15. BEGIN
  16.  
  17.  
  18.    
  19.     declare @SecuenciaBien varchar(max)
  20.    
  21.     declare @SecuenciaOtorgante varchar(max)
  22.    
  23.     declare @idRegDesdeTipoReg int
  24.    
  25.  
  26.     set @SecuenciaBien = ''
  27.    
  28.     set @idRegDesdeTipoReg = case @tiporegistro when 1 then 6 when 2 then 9 else 11 end
  29.  
  30.     delete from dbo.SecuenciaOtorgante
  31.             DBCC CHECKIDENT ('SecuenciaOtorgante', RESEED, 0)
  32.            
  33.             declare @cuentaPorcj int,
  34.                     @idexpactox int,
  35.                     @auxIdExpActo int,
  36.                     @auxDefTipoInterv varchar(2),
  37.                     @TaTipoDefInterv varchar(2)
  38.             set @cuentaPorcj = 0
  39.             set @idexpactox = 0
  40.             set @TaTipoDefInterv = ''
  41.  
  42.             set @auxIdExpActo = 0
  43.             set @auxDefTipoInterv = ''
  44.            
  45.             declare @xParticipacion table (
  46.                 Ta_DefTipoInterv varchar(2),
  47.                 Td_IdExpedienteActo int,
  48.                 CountPersona int
  49.             )
  50.  
  51.             insert into @xParticipacion
  52.                     select c.Ta_DefTipoInterv, a.Td_IdExpedienteActo, COUNT(a.tp_idpersona) as CountPersona
  53.                     from sn.td_expediente_interv as a
  54.                         inner join sn.tp_tipointerv as c on a.Tp_IdTipointerv = c.Tp_IdTipoInterv
  55.                         inner join SN.Tm_Escritura as d on a.Tm_IdExpediente = d.Tm_IdExpediente
  56.                         inner join SN.Td_Expediente_Acto as e on a.Td_IdExpedienteActo = e.Td_idexpedienteacto
  57.                         inner join SN.Tp_Actos as f on e.Tp_idacto = f.Tp_IdActo
  58.                     where c.Ta_DefTipoInterv in ('00', '01') and c.Tp_IdTipointerv <> 15 and MONTH(d.Tm_FechaGenEsc) = @mes and YEAR(d.Tm_FechaGenEsc) = @anho
  59.                      and d.Tm_idRegistro = @idRegDesdeTipoReg
  60.                     and not f.Ta_NatActo is null
  61.                     and not f.Tp_IdActo in (17, 24, 33, 104, 34, 147, 47, 125, 148, 119,
  62.                     40,
  63.                     39,
  64.                     38,
  65.                     37,
  66.                     36,
  67.                     35)
  68.                     and not d.Tm_idescritura in (4717, 4744, 5696, 6354, 6476, 6482, 6541, 7126, 7152, 7380, 8085, 8147, 8151, 8154, 8163, 8198, 8244, 8304, 8489, 8516) --- ESCRITURAS EXCLUIDAS
  69.                     group by c.Ta_DefTipoInterv, a.Td_IdExpedienteActo
  70.                    
  71.     if @tiporegistro = 2
  72.         begin
  73.  
  74.  
  75.             select
  76.             --ROW_NUMBER() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS Item,
  77.             DENSE_RANK()  OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS ItemByEsc,
  78.             'I: Inicial' as TipoEnvioRO,
  79.             case a.Tm_idRegistro when 6 then 'E : Escritura Pública' when 9 then 'T : Actas De Transferencia De Bienes Muebles Registrables' else 'G : Constitución De Garantía Mobiliaria Y Otras Afectaciones Sobre Bienes Muebles' end as tipoesc,
  80.              convert(int, SUBSTRING(a.Tm_NumeroEscritura, 6, 5)) nroescritura,
  81.                                 SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaNum,
  82.                                 '' NroIPNPAclara,
  83.                                 '' FechaIPNPAclara,
  84.                                 'C: Concluida' Conclusion,
  85.                                 SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaFirmaParticip,
  86.                                 'U: Única' ModalidadOpe,
  87.                                 '' CantMultiOpe,
  88.                                 '' Representante,
  89.                                 case i.Ta_DefTipoInterv when '00' then 'O: Ordenante /Propietario' else '' end PersonaOtorgante,
  90.                                 case i.Ta_DefTipoInterv when '01' then 'B: Beneficiario /Adquirente' else '' end PersonaOtorgado,
  91.                                 '' PersonaRepresenta,
  92.                                 '' TipoRepresentacion,
  93.                                 --SYSMART.ObtenerNaturalezaTaTabla(h.Ta_TipoIdentifica, 'Ta_TipoIdentifica') as TipoDoc,
  94.                                 case h.Tp_Idtipopers when '00' then '' else '1: Residente' end as CondicionResidencia,
  95.                                 case h.Tp_Idtipopers when '00' then '3: Jurídica' else '1: Natural' end as TipoPersona,
  96.                                 case h.Tp_Idtipopers when '00' then '' else l.Ta_codigoROF + ': ' + l.Ta_nombreRof end as TipoDocumentoNat,
  97.                                 case h.Tp_Idtipopers when '00' then '' else h.Numero end as NroDocNat,
  98.                                 case h.Tp_Idtipopers when '00' then h.Numero else '' end as NroDocJur,
  99.                                 case h.Tp_Idtipopers when '00' then h.RazonSocial else h.ApePaterno end as RazSocialOrApePaterno,
  100.                                 case h.Tp_Idtipopers when '00' then '' else h.ApeMaterno end as ApeMaterno,
  101.                                 case h.Tp_Idtipopers when '00' then '' else h.Nombres end as Nombres,
  102.                                 case h.Tp_Idtipopers when '00' then '' else m.Ta_codigoROF + ': ' + m.Ta_nombreRof end as Nacionalidad,
  103.                                 case h.Tp_Idtipopers when '00' then '' else SN.fc_formatearFecha('02', h.FechaNoC) end as FechaNac,
  104.                                 case h.Tp_Idtipopers when '00' then '' else n.Ta_codigoROF + ': ' + n.Ta_nombreRof end as EstadoCivil,
  105.                                 case h.Tp_Idtipopers when '00' then '' else h.CodOcupacionRO + ': ' + h.DescOcupacionRO end as OcupacionRO,
  106.                                 case h.Tp_Idtipopers when '00' then '' else case h.CodOcupacionRO when '999' then case len(rtrim(LTRIM(h.Tp_NombreOcupacion))) when 0 then 'INDEPENDIENTE' else h.  Tp_NombreOcupacion end else '' END end as DescripOcupacion,
  107.                 '' CIIU,
  108.                 '' CodCargo,
  109.                 '' CodZonaRegistral,
  110.                 '' NroPartidaRegistral,
  111.                 h.Direccion,
  112.                 oDep1.Tm_CodigoROF + ': ' + oDep1.tm_nombreROF as Departamento,
  113.                 oProv2.Tm_CodigoROF + ': ' + oProv2.tm_nombreROF as Provincia,
  114.                 oDist.Tm_CodigoROF + ': ' + oDist.tm_nombreROF as Distrito,
  115.                 '' Telefono,
  116.                 '' ParticipaConyuge,
  117.                 '' ApePaternoConyuge,
  118.                 '' ApeMaternoConyuge,
  119.                 '' NombresConyuge,
  120.                 r.Ta_codigoROF + ': ' + r.Ta_nombreRof as MedioPago,
  121.                 c.Tp_codigoROF + ': ' + c.Tp_nombreROF as TipoOperacion,
  122.                 q.tm_codigoROF + ': ' + q.tm_nombreROF as FormaPago,
  123.                 '99: Otro' as OportunidadPago,
  124.                 'Con anterioridad a la firma del IP' as DescripOportuPago,
  125.                 case h.Tp_Idtipopers when '00' then '' else case i.Tp_IdTipoInterv when 15 then '' else 'Ahorro de trabajo' end end as OrigenDinero,
  126.                 s.tm_codigoROF + ': ' + s.tm_nombreROF as Moneda,
  127.                 CONVERT(varchar(20), convert(money, p.Td_ValorExpVeh), 1) as MontoOperacion,
  128.                 CONVERT(varchar(20), convert(money, p.Td_ValorExpVeh / j.CountPersona), 1) as MontoPorParticipante,
  129.                 CONVERT(varchar(20), convert(money, p.Td_ValorExpVeh), 1) as MontoRelacionado,
  130.                 CASE p.Tm_IdMoneda when 1 then '' when 2 then '2.821' when 3 then '3.521' end TipoCambio,
  131.                 'I: Inscrito' InscripcionBien,
  132.                 case b.tp_idacto when 54 then '02: Chiclayo' else '09: Lima' end as CodZonaRegistral,
  133.                 t.Tp_PlacavVehiculo as Partida
  134.                 --,
  135.                 --              convert(varchar(max), round(100 / j.CountPersona, 2)) as porcentaje,
  136.                 --                  j.CountPersona ,
  137.                 --                  b.Td_idexpedienteacto,
  138.                 --                  i.Ta_DefTipoInterv
  139.                                 from SN.Tm_Escritura  as a
  140.                                     inner join SN.Td_Expediente_Acto as b on a.Tm_IdExpediente = b.Tm_idexpediente
  141.                                     inner join SN.Tp_Actos as c on b.Tp_idacto = c.Tp_IdActo
  142.                                     inner join SN.Td_Expediente_Interv as f on b.Td_idexpedienteacto = f.Td_IdExpedienteActo
  143.                                     inner join SN.vstInterviniente2 as h on f.Tp_IdPersona = h.Tp_idpersona
  144.                                     inner join SN.Tp_TipoInterv as i on f.Tp_IdTipointerv = i.Tp_IdTipoInterv
  145.                                     inner join @xParticipacion j on b.Td_idexpedienteacto = j.Td_IdExpedienteActo and i.Ta_DefTipoInterv = j.Ta_DefTipoInterv
  146.                                     inner join SYSMART.dbo.ta_tabla as l on h.Ta_TipoIdentifica = l.ta_codigo and l.ta_campo = 'Ta_TipoIdentifica'
  147.                                     left join SYSMART.dbo.ta_tabla as m on h.Ta_Nacionalidad = m.ta_codigo and m.ta_campo = 'Ta_Nacionalidad'
  148.                                     left join SYSMART.dbo.ta_tabla as n on h.Ta_EstCivil = n.ta_codigo and n.ta_campo = 'Ta_EstCivil'
  149.                                    
  150.                                     inner join SYSMART.dbo.tm_ubigeo as oDist on h.tm_idubigeo = oDist.tm_idubigeo
  151.                                     inner join SYSMART.dbo.tm_ubigeo as oProv2 on oDist.tm_refcodigo_ubi = oProv2.tm_idubigeo
  152.                                     inner join SYSMART.dbo.tm_ubigeo as oDep1 on oProv2.tm_refcodigo_ubi = oDep1.tm_idubigeo
  153.                                    
  154.                                     inner join SN.Td_Expediente_Vehiculo as p on b.Td_idexpedienteacto = p.Td_IdExpedienteActo
  155.                                     inner join SYSMART.dbo.tm_forma_pago as q on p.Tm_Idformapago = q.tm_idformapago
  156.                                    
  157.                                     inner join SYSMART.dbo.ta_tabla as r on p.Ta_MedioPago = r.ta_codigo and r.ta_campo = 'Ta_MedioPago'
  158.                                    
  159.                                     inner join SYSMART.dbo.Tm_moneda as s on p.Tm_IdMoneda = s.tm_idmoneda
  160.                                     inner join SN.Tp_Vehiculos as t on p.Tp_IdVehiculo = t.Tp_IdVehiculo
  161.                                 where  MONTH(a.Tm_FechaGenEsc) = @mes and YEAR(a.Tm_FechaGenEsc) = @anho
  162.                                     and i.Ta_DefTipoInterv in ('00', '01')
  163.                                     and f.Tp_IdTipointerv <> 15
  164.                                     and a.Tm_idRegistro = @idRegDesdeTipoReg
  165.                                     and not a.Tm_idescritura in (4717, 4744, 5696, 6354, 6476, 6482, 6541, 7126, 7152, 7380, 8085, 8147, 8151, 8154, 8163, 8198, 8244, 8304, 8489, 8516)  --- ESCRITURAS EXCLUIDAS
  166.                                     and not c.Ta_NatActo is null
  167.                                 and not c.Tp_IdActo in (17, 24, 33, 104, 34, 147, 47, 125, 148, 119,
  168.             40,
  169.             39,
  170.             38,
  171.             37,
  172.             36,
  173.             35)
  174.  
  175.             and case s.tm_codigoROF when 'PEN' then (p.Td_ValorExpVeh / 2.821) when 'USD' then p.Td_ValorExpVeh else (p.Td_ValorExpVeh / 3.521) end > 2500
  176.  
  177.         end
  178.     else if @tiporegistro = 1
  179.         begin
  180.             select
  181.             --ROW_NUMBER() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS Item,
  182.             DENSE_RANK()  OVER(ORDER BY Tm_NumeroEscritura ASC) AS ItemByEsc,
  183.             'I: Inicial' as TipoEnvioRO,
  184.             'E : Escritura Pública' as tipoesc,
  185.             convert(int, SUBSTRING(Tm_NumeroEscritura, 6, 5)) nroescritura,
  186.             SN.fc_formatearFecha('03', Tm_FechaGenEsc) as fechaNum,
  187.             '' NroIPNPAclara,
  188.             '' FechaIPNPAclara,
  189.             'C: Concluida' Conclusion,
  190.             SN.fc_formatearFecha('03', tm_fechafirmaesc) as fechaFirmaParticip,
  191.             'U: Única' ModalidadOpe,
  192.             '' CantMultiOpe,
  193.             '' Representante,
  194.             case Ta_DefTipoInterv when '00' then 'O: Ordenante /Propietario' else '' end PersonaOtorgante,
  195.             case Ta_DefTipoInterv when '01' then 'B: Beneficiario /Adquirente' else '' end PersonaOtorgado,
  196.             '' PersonaRepresenta,
  197.             '' TipoRepresentacion,
  198.             CondicionResidencia,
  199.             TipoPersona,
  200.             TipoDocumentoNat,
  201.             NroDocNat,
  202.             NroDocJur,
  203.             RazSocialOrApePaterno,
  204.             ApeMaterno,
  205.             Nombres,
  206.             Nacionalidad,
  207.             FechaNac,
  208.             EstadoCivil,
  209.             OcupacionRO,
  210.             DescripOcupacion,
  211.             '' CIIU,
  212.             '' CodCargo,
  213.             '' CodZonaRegistral,
  214.             '' NroPartidaRegistral,
  215.             Direccion,
  216.             Departamento,
  217.             Provincia,
  218.             Distrito,
  219.             '' Telefono,
  220.             '' ParticipaConyuge,
  221.             '' ApePaternoConyuge,
  222.             '' ApeMaternoConyuge,
  223.             '' NombresConyuge,
  224.             MedioPago,
  225.             TipoOperacion,
  226.             FormaPago,
  227.             '99: Otro' as OportunidadPago,
  228.                 'Con anterioridad a la firma del IP' as DescripOportuPago,
  229.                 case Tp_Idtipopers when '00' then '' else case Tp_IdTipoInterv when 15 then '' else 'Ahorro de trabajo' end end as OrigenDinero,
  230.                 Moneda,
  231.                 MontoOperacion,
  232.                 MontoPorParticipante,
  233.                 MontoRelacionado,
  234.                 TipoCambio,
  235.                 'I: Inscrito' InscripcionBien,
  236.                 CodZonaRegistral,
  237.                 Partida,
  238.             * from (
  239.            
  240.             select a.Tm_NumeroEscritura,
  241.                                 a.Tm_FechaGenEsc,
  242.                                 a.tm_fechafirmaesc,
  243.                                 i.Ta_DefTipoInterv,
  244.                                 h.Tp_Idtipopers,
  245.                                 i.Tp_IdTipoInterv,
  246.                                 --SYSMART.ObtenerNaturalezaTaTabla(h.Ta_TipoIdentifica, 'Ta_TipoIdentifica') as TipoDoc,
  247.                                 case h.Tp_Idtipopers when '00' then '' else '1: Residente' end as CondicionResidencia,
  248.                                 case h.Tp_Idtipopers when '00' then '3: Jurídica' else '1: Natural' end as TipoPersona,
  249.                                 case h.Tp_Idtipopers when '00' then '' else l.Ta_codigoROF + ': ' + l.Ta_nombreRof end as TipoDocumentoNat,
  250.                                 case h.Tp_Idtipopers when '00' then '' else h.Numero end as NroDocNat,
  251.                                 case h.Tp_Idtipopers when '00' then h.Numero else '' end as NroDocJur,
  252.                                 case h.Tp_Idtipopers when '00' then h.RazonSocial else h.ApePaterno end as RazSocialOrApePaterno,
  253.                                 case h.Tp_Idtipopers when '00' then '' else h.ApeMaterno end as ApeMaterno,
  254.                                 case h.Tp_Idtipopers when '00' then '' else h.Nombres end as Nombres,
  255.                                 case h.Tp_Idtipopers when '00' then '' else m.Ta_codigoROF + ': ' + m.Ta_nombreRof end as Nacionalidad,
  256.                                 case h.Tp_Idtipopers when '00' then '' else SN.fc_formatearFecha('02', h.FechaNoC) end as FechaNac,
  257.                                 case h.Tp_Idtipopers when '00' then '' else n.Ta_codigoROF + ': ' + n.Ta_nombreRof end as EstadoCivil,
  258.                                 case h.Tp_Idtipopers when '00' then '' else h.CodOcupacionRO + ': ' + h.DescOcupacionRO end as OcupacionRO,
  259.                                 case h.Tp_Idtipopers when '00' then '' else case h.CodOcupacionRO when '999' then case len(rtrim(LTRIM(h.Tp_NombreOcupacion))) when 0 then 'INDEPENDIENTE' else h.  Tp_NombreOcupacion end else '' END end as DescripOcupacion,
  260.                
  261.                 h.Direccion,
  262.                 oDep1.Tm_CodigoROF + ': ' + oDep1.tm_nombreROF as Departamento,
  263.                 oProv2.Tm_CodigoROF + ': ' + oProv2.tm_nombreROF as Provincia,
  264.                 oDist.Tm_CodigoROF + ': ' + oDist.tm_nombreROF as Distrito,
  265.                
  266.                 r.Ta_codigoROF + ': ' + r.Ta_nombreRof as MedioPago,
  267.                 c.Tp_codigoROF + ': ' + c.Tp_nombreROF as TipoOperacion,
  268.                 q.tm_codigoROF + ': ' + q.tm_nombreROF as FormaPago,
  269.                
  270.                
  271.                 s.tm_codigoROF + ': ' + s.tm_nombreROF as Moneda,
  272.                 CONVERT(varchar(20), convert(money, p.Td_ValorExpTrans), 1) as MontoOperacion,
  273.                 CONVERT(varchar(20), convert(money, p.Td_ValorExpTrans / j.CountPersona), 1) as MontoPorParticipante,
  274.                 CONVERT(varchar(20), convert(money, p.Td_ValorExpTrans), 1) as MontoRelacionado,
  275.                 CASE p.Tm_IdMoneda when 1 then '' when 2 then '2.821' when 3 then '3.521' end TipoCambio,
  276.                
  277.                 u.Tp_codigoROF + ': ' + u.Tp_nombreROF as CodZonaRegistral,
  278.                 t.Tp_Partida as Partida
  279.                 --,
  280.                 --              convert(varchar(max), round(100 / j.CountPersona, 2)) as porcentaje,
  281.                 --                  j.CountPersona ,
  282.                 --                  b.Td_idexpedienteacto,
  283.                 --                  i.Ta_DefTipoInterv
  284.                                 from SN.Tm_Escritura  as a
  285.                                     inner join SN.Td_Expediente_Acto as b on a.Tm_IdExpediente = b.Tm_idexpediente
  286.                                     inner join SN.Tp_Actos as c on b.Tp_idacto = c.Tp_IdActo
  287.                                     inner join SN.Td_Expediente_Interv as f on b.Td_idexpedienteacto = f.Td_IdExpedienteActo
  288.                                     inner join SN.vstInterviniente2 as h on f.Tp_IdPersona = h.Tp_idpersona
  289.                                     inner join SN.Tp_TipoInterv as i on f.Tp_IdTipointerv = i.Tp_IdTipoInterv
  290.                                     inner join @xParticipacion j on b.Td_idexpedienteacto = j.Td_IdExpedienteActo and i.Ta_DefTipoInterv = j.Ta_DefTipoInterv
  291.                                     inner join SYSMART.dbo.ta_tabla as l on h.Ta_TipoIdentifica = l.ta_codigo and l.ta_campo = 'Ta_TipoIdentifica'
  292.                                     left join SYSMART.dbo.ta_tabla as m on h.Ta_Nacionalidad = m.ta_codigo and m.ta_campo = 'Ta_Nacionalidad'
  293.                                     left join SYSMART.dbo.ta_tabla as n on h.Ta_EstCivil = n.ta_codigo and n.ta_campo = 'Ta_EstCivil'
  294.                                    
  295.                                     inner join SYSMART.dbo.tm_ubigeo as oDist on h.tm_idubigeo = oDist.tm_idubigeo
  296.                                     inner join SYSMART.dbo.tm_ubigeo as oProv2 on oDist.tm_refcodigo_ubi = oProv2.tm_idubigeo
  297.                                     inner join SYSMART.dbo.tm_ubigeo as oDep1 on oProv2.tm_refcodigo_ubi = oDep1.tm_idubigeo
  298.                                    
  299.                                     inner join SN.Td_Expediente_Transferencia as p on b.Td_idexpedienteacto = p.Td_IdExpedienteActo
  300.                                     inner join SYSMART.dbo.tm_forma_pago as q on p.Tm_Idformapago = q.tm_idformapago
  301.                                    
  302.                                     inner join SYSMART.dbo.ta_tabla as r on p.Ta_MedioPago = r.ta_codigo and r.ta_campo = 'Ta_MedioPago'
  303.                                    
  304.                                     inner join SYSMART.dbo.Tm_moneda as s on p.Tm_IdMoneda = s.tm_idmoneda
  305.                                     inner join SN.Tp_Predios as t on p.Tp_IdBien = t.Tp_IdPredio
  306.                                     inner join SN.Tp_OficinaReg as u on t.Tp_IdOficinaReg = u.Tp_IdOficinaReg
  307.                                 where  MONTH(a.Tm_FechaGenEsc) = @mes and YEAR(a.Tm_FechaGenEsc) = @anho
  308.                                     and i.Ta_DefTipoInterv in ('00', '01')
  309.                                     and f.Tp_IdTipointerv <> 15
  310.                                     and a.Tm_idRegistro = @idRegDesdeTipoReg
  311.                                     and not a.Tm_idescritura in (4717, 4744, 5696, 6354, 6476, 6482, 6541, 7126, 7152, 7380, 8085, 8147, 8151, 8154, 8163, 8198, 8244, 8304, 8489, 8516)  --- ESCRITURAS EXCLUIDAS
  312.                                                                 and not c.Ta_NatActo is null
  313.                             and b.Tp_idacto not in (35, 36, 37, 38, 39, 40)
  314.                             and case s.tm_codigoROF when 'PEN' then (p.Td_ValorExpTrans / 2.821) when 'USD' then p.Td_ValorExpTrans else (p.Td_ValorExpTrans / 3.521) end > 2500
  315.        
  316.                            
  317.     ) as x
  318.         end
  319.     else
  320.         begin
  321.             select
  322.             --ROW_NUMBER() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS Item,
  323.             DENSE_RANK()  OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS ItemByEsc,
  324.             'I: Inicial' as TipoEnvioRO,
  325.             case a.Tm_idRegistro when 6 then 'E : Escritura Pública' when 9 then 'T : Actas De Transferencia De Bienes Muebles Registrables' else 'G : Constitución De Garantía Mobiliaria Y Otras Afectaciones Sobre Bienes Muebles' end as tipoesc,
  326.              convert(int, SUBSTRING(a.Tm_NumeroEscritura, 6, 5)) nroescritura,
  327.                                 SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaNum,
  328.                                 '' NroIPNPAclara,
  329.                                 '' FechaIPNPAclara,
  330.                                 'C: Concluida' Conclusion,
  331.                                 SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaFirmaParticip,
  332.                                 'U: Única' ModalidadOpe,
  333.                                 '' CantMultiOpe,
  334.                                 '' Representante,
  335.                                 case i.Ta_DefTipoInterv when '00' then 'O: Ordenante /Propietario' else '' end PersonaOtorgante,
  336.                                 case i.Ta_DefTipoInterv when '01' then 'B: Beneficiario /Adquirente' else '' end PersonaOtorgado,
  337.                                 '' PersonaRepresenta,
  338.                                 '' TipoRepresentacion,
  339.                                 --SYSMART.ObtenerNaturalezaTaTabla(h.Ta_TipoIdentifica, 'Ta_TipoIdentifica') as TipoDoc,
  340.                                 case h.Tp_Idtipopers when '00' then '' else '1: Residente' end as CondicionResidencia,
  341.                                 case h.Tp_Idtipopers when '00' then '3: Jurídica' else '1: Natural' end as TipoPersona,
  342.                                 case h.Tp_Idtipopers when '00' then '' else l.Ta_codigoROF + ': ' + l.Ta_nombreRof end as TipoDocumentoNat,
  343.                                 case h.Tp_Idtipopers when '00' then '' else h.Numero end as NroDocNat,
  344.                                 case h.Tp_Idtipopers when '00' then h.Numero else '' end as NroDocJur,
  345.                                 case h.Tp_Idtipopers when '00' then h.RazonSocial else h.ApePaterno end as RazSocialOrApePaterno,
  346.                                 case h.Tp_Idtipopers when '00' then '' else h.ApeMaterno end as ApeMaterno,
  347.                                 case h.Tp_Idtipopers when '00' then '' else h.Nombres end as Nombres,
  348.                                 case h.Tp_Idtipopers when '00' then '' else m.Ta_codigoROF + ': ' + m.Ta_nombreRof end as Nacionalidad,
  349.                                 case h.Tp_Idtipopers when '00' then '' else SN.fc_formatearFecha('02', h.FechaNoC) end as FechaNac,
  350.                                 case h.Tp_Idtipopers when '00' then '' else n.Ta_codigoROF + ': ' + n.Ta_nombreRof end as EstadoCivil,
  351.                                 case h.Tp_Idtipopers when '00' then '' else h.CodOcupacionRO + ': ' + h.DescOcupacionRO end as OcupacionRO,
  352.                                 case h.Tp_Idtipopers when '00' then '' else case h.CodOcupacionRO when '999' then case len(rtrim(LTRIM(h.Tp_NombreOcupacion))) when 0 then 'INDEPENDIENTE' else h.  Tp_NombreOcupacion end else '' END end as DescripOcupacion,
  353.                 '' CIIU,
  354.                 '' CodCargo,
  355.                 '' CodZonaRegistral,
  356.                 '' NroPartidaRegistral,
  357.                 h.Direccion,
  358.                 oDep1.Tm_CodigoROF + ': ' + oDep1.tm_nombreROF as Departamento,
  359.                 oProv2.Tm_CodigoROF + ': ' + oProv2.tm_nombreROF as Provincia,
  360.                 oDist.Tm_CodigoROF + ': ' + oDist.tm_nombreROF as Distrito,
  361.                 '' Telefono,
  362.                 '' ParticipaConyuge,
  363.                 '' ApePaternoConyuge,
  364.                 '' ApeMaternoConyuge,
  365.                 '' NombresConyuge,
  366.                 '02: Cheque' as MedioPago,
  367.                 c.Tp_codigoROF + ': ' + c.Tp_nombreROF as TipoOperacion,
  368.                 'P: A Plazos (Más De Una Cuota)' as FormaPago,
  369.                 '99: Otro' as OportunidadPago,
  370.                 'Con anterioridad a la firma del IP' as DescripOportuPago,
  371.                 case h.Tp_Idtipopers when '00' then '' else case i.Tp_IdTipoInterv when 15 then '' else 'Ahorro de trabajo' end end as OrigenDinero,
  372.                 s.tm_codigoROF + ': ' + s.tm_nombreROF as Moneda,
  373.                 CONVERT(varchar(20), convert(money, p.Td_MontoGravamen), 1) as MontoOperacion,
  374.                 CONVERT(varchar(20), convert(money, p.Td_MontoGravamen/ j.CountPersona), 1) as MontoPorParticipante,
  375.                 CONVERT(varchar(20), convert(money, p.Td_MontoGravamen), 1) MontoRelacionado,
  376.                 CASE p.Tm_IdMoneda when 1 then '' when 2 then '2.821' when 3 then '3.521' end TipoCambio,
  377.                 'I: Inscrito' InscripcionBien,
  378.                 case b.tp_idacto when 54 then '02: Chiclayo' else '09: Lima' end as CodZonaRegistral,
  379.                 t.Tp_PlacavVehiculo as Partida
  380.                 --,
  381.                 --              convert(varchar(max), round(100 / j.CountPersona, 2)) as porcentaje,
  382.                 --                  j.CountPersona ,
  383.                 --                  b.Td_idexpedienteacto,
  384.                 --                  i.Ta_DefTipoInterv
  385.                                 from SN.Tm_Escritura  as a
  386.                                     inner join SN.Td_Expediente_Acto as b on a.Tm_IdExpediente = b.Tm_idexpediente
  387.                                     inner join SN.Tp_Actos as c on b.Tp_idacto = c.Tp_IdActo
  388.                                     inner join SN.Td_Expediente_Interv as f on b.Td_idexpedienteacto = f.Td_IdExpedienteActo
  389.                                     inner join SN.vstInterviniente2 as h on f.Tp_IdPersona = h.Tp_idpersona
  390.                                     inner join SN.Tp_TipoInterv as i on f.Tp_IdTipointerv = i.Tp_IdTipoInterv
  391.                                     inner join @xParticipacion j on b.Td_idexpedienteacto = j.Td_IdExpedienteActo and i.Ta_DefTipoInterv = j.Ta_DefTipoInterv
  392.                                     inner join SYSMART.dbo.ta_tabla as l on h.Ta_TipoIdentifica = l.ta_codigo and l.ta_campo = 'Ta_TipoIdentifica'
  393.                                     left join SYSMART.dbo.ta_tabla as m on h.Ta_Nacionalidad = m.ta_codigo and m.ta_campo = 'Ta_Nacionalidad'
  394.                                     left join SYSMART.dbo.ta_tabla as n on h.Ta_EstCivil = n.ta_codigo and n.ta_campo = 'Ta_EstCivil'
  395.                                    
  396.                                     inner join SYSMART.dbo.tm_ubigeo as oDist on h.tm_idubigeo = oDist.tm_idubigeo
  397.                                     inner join SYSMART.dbo.tm_ubigeo as oProv2 on oDist.tm_refcodigo_ubi = oProv2.tm_idubigeo
  398.                                     inner join SYSMART.dbo.tm_ubigeo as oDep1 on oProv2.tm_refcodigo_ubi = oDep1.tm_idubigeo
  399.                                    
  400.                                     inner join SN.Td_Expediente_Gravamen as p on b.Td_idexpedienteacto = p.Td_IdExpedienteActo
  401.                                    
  402.                                     inner join SYSMART.dbo.Tm_moneda as s on p.Tm_IdMoneda = s.tm_idmoneda
  403.                                     inner join SN.Tp_Vehiculos as t on p.Tp_idbien = t.Tp_IdVehiculo
  404.                                 where  MONTH(a.Tm_FechaGenEsc) = @mes and YEAR(a.Tm_FechaGenEsc) = @anho
  405.                                     and i.Ta_DefTipoInterv in ('00', '01')
  406.                                     and f.Tp_IdTipointerv <> 15
  407.                                     and a.Tm_idRegistro = 11
  408.         end
  409. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement