Advertisement
kuroshan1104

sp_lst_agua ORIGINAL 2017

Feb 8th, 2025
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.57 KB | Source Code | 0 0
  1. -- CODIGO ORIGINAL
  2. BEGIN
  3.  
  4. /*
  5. declare anio INT;
  6. declare mes INT;
  7. declare vigv DOUBLE;
  8. */
  9.  
  10. declare li_aniop int;
  11. declare li_mesp int;
  12. declare lperiodop_int int;
  13. declare vper int;
  14. declare vverif int;
  15. declare vperiodo, vmes char(20);
  16.  
  17.  
  18. if(mes<10) then
  19.   set vmes = concat('0',mes);
  20. ELSE
  21. set vmes = mes;
  22.  end if;
  23.  
  24. set vperiodo =concat(anio,vmes);
  25.  
  26. if mes=1 then
  27.   set li_mesp=12;
  28.   set li_aniop=anio-1;
  29. else
  30.   set li_mesp= mes - 1;
  31.   set li_aniop=anio;
  32. end if;
  33.  
  34. set lperiodop_int = li_aniop * 100 + li_mesp;
  35. set vper = anio * 100 + mes;
  36.  
  37. SELECT count(idpuesto) INTO vverif
  38. FROM p_lecturas WHERE ( p_lecturas.periodo = concat(anio,repeat('0',2-length(mes)),mes) ) AND ( p_lecturas.tipo = aserv )  ;
  39.  
  40. if vverif=0 then
  41.      if (select count(*) from g_recibo_cargos where idconcepto=7 and periodo = vperiodo )=0 then
  42.             INSERT INTO  g_recibo_cargos(`idconcepto`, `periodo`, `m_desague_carne`, `m_desague_otros`)
  43.             VALUES (7, vperiodo, 10, 5);
  44.         end if;
  45.  
  46.   SELECT p.idpuesto,p.codigo, p.codigo_ant,(SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1) as idsocio,
  47.   f_g_nombres((SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1)) as wnombres,
  48.   if(vcf=1, (select lect_ant from cargo_fijo_agua where id =s.idcargofijo),
  49.    ifnull(l.lectura_ant, ifnull((select lectura_actual from p_lecturas where idpuesto= p.idpuesto and periodo= lperiodop_int and tipo= aserv),0))) as lectura_ant,
  50.    -- baja 07.12.19 if(vcf=1, IF(f_have_corte_agua(p.idpuesto)>0,0,(select lect_act from cargo_fijo_agua where id =s.idcargofijo)), l.lectura_actual) as lectura_actual,
  51.     if(vcf=1, IF(0>0,0,(select lect_act from cargo_fijo_agua where id =s.idcargofijo)), l.lectura_actual) as lectura_actual,  
  52.      
  53.  
  54.   if(vcf=1, (select lect_dif from cargo_fijo_agua where id =s.idcargofijo), ifnull(l.lectura_dif,0)) as diferencia,
  55.   '' as tension, l.e_tipo as tipo, e_apublico as e_apublico,l.e_gastos as gastos, l.e_mant as mant,
  56.   ifnull(l.igv,0) as igv, ifnull(l.cargo,vfactor) as cargo,l.num_recibo, 0 as sw,
  57.   1 as a_tipo, 'M3' as a_vol, ifnull(l.reposicion,0) as reposicion,
  58.   f_get_cargo_desague_periodo(vperiodo, p.idpuesto) as m_desague,
  59.     f_get_giro(p.idgiro) as giro
  60.  
  61.  
  62.   FROM p_puesto p
  63.   join p_puesto_servicio s on p.idpuesto=s.idpuesto and s.idservicio=aserv and s.activo=1 and p.activo=1
  64.   left outer join p_lecturas l on p.idpuesto=l.idpuesto
  65.   and l.periodo= concat(anio,repeat('0',2-length(mes)),mes) and l.tipo=aserv
  66.   order by p.codigo;
  67.  
  68. else
  69.  
  70.   SELECT p.idpuesto,p.codigo, p.codigo_ant,
  71.     l.idsocio,  
  72.     f_g_nombres(l.idsocio) as wnombres,
  73.   -- (SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1) as idsocio,
  74.   -- f_g_nombres((SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1)) as wnombres,
  75.   ifnull(l.lectura_ant,(select lectura_actual from p_lecturas where idpuesto= p.idpuesto and periodo= lperiodop_int and tipo= aserv)) as lectura_ant,
  76.   l.lectura_actual, ifnull(l.lectura_dif,0) as diferencia,'' as tension,l.e_tipo as tipo, e_apublico as e_apublico,l.e_gastos as gastos, l.e_mant as mant,
  77.   ifnull(l.igv,0) as igv, ifnull(l.cargo,0) as cargo,l.num_recibo, 0 as sw,
  78.   l.a_tipo, l.a_vol, ifnull(l.reposicion,0) as reposicion, l.m_desague,
  79.     f_get_giro(p.idgiro) as giro
  80.  
  81.   FROM p_lecturas l
  82.   join p_puesto p on p.idpuesto=l.idpuesto and l.periodo= concat(anio,repeat('0',2-length(mes)),mes) and de_baja=0 -- and p.activo=1
  83.   left outer join p_puesto_servicio s on p.idpuesto=s.idpuesto
  84.   and s.idservicio=aserv where l.tipo=aserv /*and s.activo=1*/
  85.   order by p.codigo;
  86.  
  87. end if;
  88.  
  89. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement