Advertisement
kuroshan1104

sp_cod_agua_imp_rec

Sep 25th, 2023
1,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.32 KB | None | 0 0
  1. BEGIN
  2. -- recibo general de luz ;
  3. -- declare vperiodo varchar(6);
  4. declare vfvence date;
  5. declare vfcorte date;
  6. declare vfemision date;
  7. declare vflectura date;
  8. declare vfactor double;
  9. declare vigv double;
  10. -- set vperiodo='201501';
  11.  
  12. select f_vence,f_corte,f_emision,factor,igv, f_lectura
  13. into vfvence,vfcorte,vfemision,vfactor,vigv, vflectura
  14. from g_recibo where periodo=vperiodo and tipo='E';
  15.  
  16. SELECT l.periodo,vfvence,vfcorte,f_g_nombres(l.idsocio) as nombres,l.num_recibo,p.codigo, p.codigo_ant,
  17. (SELECT des_giro FROM p_giro where idgiro= p.idgiro) as giro,
  18. l.e_tension, IF(l.e_tipo=1,'Monofásica', 'Trifásica') as tipo, l.lectura_ant, l.lectura_actual,l.lectura_dif,vfemision,vigv,
  19. l.cargo, l.igv,l.e_apublico,l.e_gastos,l.e_mant,l.total,
  20. (SELECT COALESCE(sum(saldo),0) FROM d_deuda d
  21.  join d_deuda_puesto dp on d.ideuda=dp.ideuda
  22.  WHERE dp.idpuesto=p.idpuesto and d.idconcepto=6
  23.  and estado='DE' and d.condicion = 1 and isnull(d.idfracc )
  24.  and d.idperiodo < (select x.idperiodo from d_periodo x where x.anio= MID(vperiodo,1,4) and x.nperiodo= MID(vperiodo,5,6) and x.idf='M' )
  25. ) as wsaldo,
  26.  
  27. (select group_concat(' ',f_get_nmes(month(d.f_ini)),'-',year(d.f_ini))
  28.  from d_deuda d join d_deuda_puesto sp on sp.ideuda=d.ideuda
  29.  where sp.idpuesto=p.idpuesto and d.saldo>0 and d.estado<>'XX'
  30.  and d.condicion=1 and d.idconcepto=6 and isnull(d.idfracc)
  31.  and d.idperiodo < (select x.idperiodo from d_periodo x where x.anio= MID(vperiodo,1,4)
  32.  and x.nperiodo= MID(vperiodo,5,6) and x.idf='M' )
  33.  ) as glosa,
  34.  l.reposicion  , l.redondeo ,'',  vflectura ,
  35. (select sum(d.saldo)
  36.  from d_deuda d join d_deuda_puesto sp on sp.ideuda=d.ideuda
  37.  where sp.idpuesto=p.idpuesto and d.saldo>0 and d.estado<>'XX'
  38.  and d.condicion=1 and d.idconcepto=24 and isnull(d.idfracc)
  39.  GROUP BY sp.idpuesto)  AS inst_luz,
  40. (select sum(d.saldo)
  41.  from d_deuda d join d_deuda_puesto sp on sp.ideuda=d.ideuda
  42.  where sp.idpuesto=p.idpuesto and d.saldo>0 and d.estado<>'XX'
  43.  and d.condicion=1 and d.idconcepto=298 and isnull(d.idfracc)
  44.  GROUP BY sp.idpuesto) as md_cambio
  45.                                                                    
  46.  FROM p_lecturas l
  47.  join p_puesto p on p.idpuesto=l.idpuesto
  48.  where l.periodo=vperiodo and l.tipo= vtipo
  49. -- and  (SELECT des_giro FROM p_giro where idgiro= p.idgiro)='CARNES Y POLLOS'
  50.   order by p.codigo;
  51.  
  52. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement