Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CODIGO ORIGINAL
- BEGIN
- /*
- declare anio INT;
- declare mes INT;
- declare vigv DOUBLE;
- */
- declare li_aniop int;
- declare li_mesp int;
- declare lperiodop_int int;
- declare vper int;
- declare vverif int;
- declare vperiodo, vmes char(20);
- if(mes<10) then
- set vmes = concat('0',mes);
- ELSE
- set vmes = mes;
- end if;
- set vperiodo =concat(anio,vmes);
- if mes=1 then
- set li_mesp=12;
- set li_aniop=anio-1;
- else
- set li_mesp= mes - 1;
- set li_aniop=anio;
- end if;
- set lperiodop_int = li_aniop * 100 + li_mesp;
- set vper = anio * 100 + mes;
- SELECT count(idpuesto) INTO vverif
- FROM p_lecturas WHERE ( p_lecturas.periodo = concat(anio,repeat('0',2-length(mes)),mes) ) AND ( p_lecturas.tipo = aserv ) ;
- if vverif=0 then
- if (select count(*) from g_recibo_cargos where idconcepto=7 and periodo = vperiodo )=0 then
- INSERT INTO g_recibo_cargos(`idconcepto`, `periodo`, `m_desague_carne`, `m_desague_otros`)
- VALUES (7, vperiodo, 10, 5);
- end if;
- SELECT p.idpuesto,p.codigo, p.codigo_ant,(SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1) as idsocio,
- f_g_nombres((SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1)) as wnombres,
- if(vcf=1, (select lect_ant from cargo_fijo_agua where id =s.idcargofijo),
- 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,
- -- 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,
- if(vcf=1, IF(0>0,0,(select lect_act from cargo_fijo_agua where id =s.idcargofijo)), l.lectura_actual) as lectura_actual,
- if(vcf=1, (select lect_dif from cargo_fijo_agua where id =s.idcargofijo), 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,
- ifnull(l.igv,0) as igv, ifnull(l.cargo,vfactor) as cargo,l.num_recibo, 0 as sw,
- 1 as a_tipo, 'M3' as a_vol, ifnull(l.reposicion,0) as reposicion,
- f_get_cargo_desague_periodo(vperiodo, p.idpuesto) as m_desague,
- f_get_giro(p.idgiro) as giro
- FROM p_puesto p
- join p_puesto_servicio s on p.idpuesto=s.idpuesto and s.idservicio=aserv and s.activo=1 and p.activo=1
- left outer join p_lecturas l on p.idpuesto=l.idpuesto
- and l.periodo= concat(anio,repeat('0',2-length(mes)),mes) and l.tipo=aserv
- order by p.codigo;
- else
- SELECT p.idpuesto,p.codigo, p.codigo_ant,
- l.idsocio,
- f_g_nombres(l.idsocio) as wnombres,
- -- (SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1) as idsocio,
- -- f_g_nombres((SELECT idsocio FROM p_puesto_socio where idpuesto= p.idpuesto and activo=1)) as wnombres,
- ifnull(l.lectura_ant,(select lectura_actual from p_lecturas where idpuesto= p.idpuesto and periodo= lperiodop_int and tipo= aserv)) as lectura_ant,
- 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,
- ifnull(l.igv,0) as igv, ifnull(l.cargo,0) as cargo,l.num_recibo, 0 as sw,
- l.a_tipo, l.a_vol, ifnull(l.reposicion,0) as reposicion, l.m_desague,
- f_get_giro(p.idgiro) as giro
- FROM p_lecturas l
- 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
- left outer join p_puesto_servicio s on p.idpuesto=s.idpuesto
- and s.idservicio=aserv where l.tipo=aserv /*and s.activo=1*/
- order by p.codigo;
- end if;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement