select * from astoh where codcomp(ash_comprob)='DK';
select * from astoh where codcomp(ash_comprob)='DK' order by 1 desc;
select * from astoh where codcomp(ash_comprob)='DK' order by 1 desc limit 5;
select * from compra where cpra_id=76928;
select distinct cpra_letra from compra;
select distinct cpra_lecomp from compra;
select * from compra where cpra_lecomp='F';
select * from compra where cpra_lecomp='F' order by 1 desc;
select * from compra where cpra_lecomp='G' order by 1 desc;
select * from compra where cpra_lecomp='M' order by 1 desc;
select * from compra where cpra_lecomp='O' order by 1 desc;
select * from compra where cpra_lecomp='Z' order by 1 desc;
select distinct cpra_lecomp from compra;
select * from compra where cpra_lecomp='Z' order by 1 desc limit 1;
select * from compra where cpra_lecomp='M' order by 1 desc limit 1;
select * from compra where cpra_lecomp='O' order by 1 desc limit 1;
select * from compra where cpra_lecomp='E' order by 1 desc limit 1;
select version();
select distinct cpra_lecomp from compra where codcomp(cpra_comprob) in ('FK','FC');
select * from subitem where sitem_id=1656588;
select * from unifun where unif_codigo=225;
select * from unifun where unif_newcod='PLAYA 1';
select * from opervehi wher opv_id=349417;
select * from opervehi where opv_id=349417;
select sum(astc_importe) from astoctas where astc_idastoh=311464 and astc_ctacble not in (134,26,40,32,39,31,25) and astc_tasa=0;
select * from astoctas where astc_idastoh=311464 and astc_ctacble not in (134,26,40,32,39,31,25) and astc_tasa=0;
select * from astoctas where astc_idastoh=311464;
select * from ctacble where cbl_id=14;
select * from compras where cpra_nucomp=26022015;
select * from compra where cpra_nucomp=26022015;
select * from astoctas where astc_idastoh=311262;
select * from ctacble where cbl_id=10;
select * from usuarios where usu_codigo=6755;
select * from clientes where cli_codigo = 6755;
select * astoctas where astc_ctacte=4604 and astc_tipcta=99 order by 1 desc limit 15;
select * from astoctas where astc_ctacte=4604 and astc_tipcta=99 order by 1 desc limit 15;
update astoctas set astc_grupo=8014 where astc_id in (965271,964135);
\df+ grupocli 
select grupocli(4604,2);
update astoctas set astc_grupo=grupocli(4604,1) where astc_id=975563;
update astoctas set astc_grupo=grupocli(4604,1) where astc_id=976398;
select * from subitem where sitem_idoper=4072;
delete from subitem where sitem_id=46265;
select * from subitem where sitem_idoper=20859;
select * from retiros where ret_idopera=78125;
insert into retiros (ret_idopera,ret_idsitem,ret_item,ret_sitem,ret_cantidad) values (78125,236741,2,0,10);
select * from subitem where sitem_id=236741;
update subitem set sitem_cantret=10,sitem_cantcomp=0 where sitem_id=236741;
select * from retiros where ret_idopera=78129;
insert into retiros (ret_idopera,ret_idsitem,ret_item,ret_sitem,ret_cantidad) values (78129,236741,2,0,2);
select * from subitem where sitem_id=236741;
update subitem set sitem_cantret=12,sitem_cantcomp=0 where sitem_id=236741;
select * from retiros where ret_idopera=78132;
insert into retiros (ret_idopera,ret_idsitem,ret_item,ret_sitem,ret_cantidad) values (78132,236741,2,0,7);
update subitem set sitem_cantret=19,sitem_cantcomp=0 where sitem_id=236741;
select * from subitem where sitem_idoper=18156;
select * from retiros where ret_idopera=207016;
select * from retiros where ret_idopera=74007;
insert into retiros (ret_idopera,ret_idsitem,ret_item,ret_sitem,ret_cantidad) values (74007,207016,2,0,1);
update subitem set sitem_cantret=1,sitem_cantcomp=0 where sitem_id=207016;
select * from opervehi where opv_id=349417;
select * from opervehi where opv_id=349448;
update opervehi set opv_obs='' where opv_id=349448;
select * from opervehi order by 1 desc limit 10;
select * from controlop where ctp_idoper = 367996;
delete from opervehi where opv_id=349509;
select * from opervehi where opv_id=346573;
select * from controlop where ctp_idoper=365830;
select * from requeh;
select distinct(descprov(astc_ctacte)) from astoctas where astc_tipcta=98 and astc_fecval>'01-12-2014';
select distinct(descprov(astc_ctacte)) from astoctas where astc_tipcta=98 and astc_fecval>'01-05-2015';
select distinct(descprov(astc_ctacte)) from astoctas where astc_tipcta=98 and astc_fecval>'21-05-2015';
select distinct(descprov(astc_ctacte)) from astoctas where astc_tipcta=98 and astc_fecval>'31-05-2015';
select astc_ctacte,distinct(descprov(astc_ctacte)) from astoctas where astc_tipcta=98 and astc_fecval>'31-05-2015';
select distinct(descprov(astc_ctacte),astc_ctacte) from astoctas where astc_tipcta=98 and astc_fecval>'31-05-2015';
select distinct(descprov(astc_ctacte)),astc_ctacte from astoctas where astc_tipcta=98 and astc_fecval>'31-05-2015';
select * from astoctas where astc_ctacte=-1 and astc_tipcta=98;
select * from astoctas where astc_ctacte=-1 and astc_tipcta=98 and astc_estado=2 and astc_fecval between '01-05-2015' and '31-05-2015';
select * from astoctas where astc_ctacte=-1 and astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015';
select * from astoctas where astc_ctacte=0 and astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015';
select * from astoctas where astc_ctacte is null and astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015';
select astc_ctacte,descprov(astc_ctacte) from astoctas where astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015';
select astc_ctacte,descprov(astc_ctacte) from astoctas where astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015';
select astc_ctacte,descprov(astc_ctacte) from astoctas where astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015';
select astc_ctacte,descprov(astc_ctacte) from astoctas where astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015' and astc_ctacte=8046;
select * from astoctas where astc_tipcta=98 and astc_estado=2 and astc_fecval>'01-05-2015' and astc_ctacte=8046;
select * from astoh where ash_id=314218;
select nomopera(ash_operad) from astoh where ash_id=314218;
select * from astoctas where astc_idastoh=314218;
select * from prove where prov_nombre like '%TELEFONICA%';
update astoctas set astc_ctacte=13 where astc_id=975155;
select * from astoh where ash_fecval between '01-02-2015' and '28-02-2015' and date(ash_fecreg)>'28-02-2015' order by 1;
select * from astoctas where astc_idastoh=312737;
select * from astoh where ash_fecval between '01-02-2015' and '28-02-2015' and date(ash_fecreg)>'28-02-2015' order by 1 desc;
select * from astoh where ash_fecval between '01-02-2015' and '28-02-2015' and ash_fecori>'28-02-2015' order by 1 desc;
select * from astoh where ash_fecval between '01-02-2015' and '28-02-2015' and ash_fecomp>'28-02-2015' order by 1 desc;
select * from ctacble where cbl_nombre like '%IVA%';
select * from ctacble where cbl_nombre like '%I.V.A%';
select * from astoctas where (astc_importe=360 or astc_importe=-360) and astc_fecval>'31-01-2015';
select * from ctacble where cbl_id=242;
select * from astoctas where astc_idastoh=311336;
select * from ctacble where cbl_id=260;
select * from ctacble where cbl_nombre like '%SIRC%';
select * from ctacble where cbl_nombre like '%S.I.R.C%';
select * from requeb;
select * from requeh;
delete from requeh where rh_id=34;
delete from requeb where rb_idrh=34;
delete from requeh where rh_id=34;
update requeh set rh_numero=1791 where rh_id=30;
select * from requeh;
update requeh set rh_estado=999;
update requeb set rb_estado=999;
selec * from och;
select * from och;
select * from contratos where contr_dispos = '317/15';
select * from operaciones where op_id=368096;
select * from unifun where unif_codigo=171;
select * from operaciones where op_id=368097;
select cambio_estado(368097,101::int2,1::int2);
select * from operaciones where op_id=368097;
select cambio_estado(368097,1::int2,1::int2);
select * from carvis;
select * from carvis limit 10;
select * from carvis order by 1 desc limit 10;
select * from operadores where operad_id=238;
select * from carvis order by 1 desc limit 10;
update carvis set cvt_fecdes='17-06-2015' where cvt_id=120668;
select * from carvis order by 1 desc limit 10;
select * from gente where gte_id=30056;
update gente set gte_fecdes='17-06-2015' where gte_id=30056;
update carvis set cvt_fechas='17-06-2015' where cvt_id=120668;
alter table tarjvisita alter column tj_estado set default 1;
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251122,1);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251123,2);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251124,3);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251125,4);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251126,5);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251127,6);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251128,7);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251129,8);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251130,9);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251131,10);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251132,11);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251133,12);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251134,13);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251135,14);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251136,15);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251137,16);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251138,17);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251139,18);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251140,19);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251141,20);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251142,21);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251143,22);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251144,23);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251145,24);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251146,25);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251147,26);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251148,27);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251149,28);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251150,29);
insert into tarjvisita (tj_nroreal,tj_nrovis) values (2251151,30);
select * from tarjvisita;
select tj_nrovis|| - || case when tj_estado=1 then 'Disponible' when tj_estado=2 then 'Utilizada' else 'Otro' from tarjvisita;
select tj_nrovis|| - || case when tj_estado=1 then 'Disponible' when tj_estado=2 then 'Utilizada' else 'Otro' end from tarjvisita;
select tj_nrovis||' - '|| case when tj_estado=1 then 'Disponible' when tj_estado=2 then 'Utilizada' else 'Otro' end from tarjvisita;
select * from visita order by 1 desc limit 10;
select * from inout where io_id=982148;
select * from gente where gte_id=6407;
\df+ trato
select * from tipgente;
select * from visita order by 1 desc limit 10;
select * from inout where io_id=982470;
select * from gente where gte_id=30056;
\d+ inout
select * from lecting order by 1 desc limit 5;
select * from gente where gte_id=30056;
select * from tarjvisita;
select * from tarjvisita;
select * from tarjvisita;
select * from gente where gte_tarjeta in (select tj_nroreal from tarjvisita);
select * from inout where io_tarje in (select tj_nroreal from tarjvisita);
delete from inout where io_gente=30056;
delete from visita where vt_gente=30056;
delete from livianos where lv_gente = 30056;
delete from gente where gte_id=30056;
delete from carvis where cvt_gente = 30056;
select * from inout order by 1 desc limit 10;
select * from gente where gte_id=10874;
select * from inout where io_gente=10874;
delete from inout where io_gente=10874;
delete from gente where gte_id=10874;
select * from gente where gte_nrodoc = 34830469;
select * from gente where gte_tarjeta in (select tj_nroreal from tarjvisita);
select * from gente where gte_nrodoc = 34830470;
delete from inout where io_gente=30058;
delete from carvis where cvt_gente = 30058;
delete from visita where vt_gente = 30058;
delete from gente where gte_id=30058;
select astc_idastoh,count(distinct(astc_estado)) from astoctas where astc_fecval>'01-06-2014' group by 1 having count(distinct(astc_estado))>1;
select astc_idastoh,sum(astc_importe) from astoctas where astc_estado=2 group by 1 having sum(astc_importe)!=0;
select codcomp(astc_comprob),astc_numero from astoctas where astc_tasa=0 and astc_ctacble=26 and astc_estado=2 and astc_fecval>'01-06-2014';
select codcomp(astc_comprob),astc_numero from astoctas where astc_tasa=0 and astc_ctacble=26 and astc_estado=2 and astc_fecval>'01-05-2015';
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK';
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK' and astc_ctacble=26;
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK' and astc_ctacble=26;
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK' and astc_ctacble=26;
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK' and astc_ctacble=26;
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK' and astc_ctacble=26;
select * from astoctas where astc_numero in (28360,28361,28362,28363) and codcomp(astc_comprob)='FK' and astc_ctacble=26;
select * from astoh where ash_fecval between '01-05-2015' and '31-05-2015' order by 1;
select * from astoh where ash_fecval between '01-05-2015' and '31-05-2015' and codcomp(ash_comprob) not in ('AD','FA','FB','CA') order by 1;
select * from astoh where ash_fecval between '01-05-2015' and '31-05-2015' and codcomp(ash_comprob) not in ('AD','FA','FB','CA','RC','Rc') order by 1;
select * from astoh where ash_fecval between '01-05-2015' and '31-05-2015' and codcomp(ash_comprob) not in ('AD','FA','FB','CA','RC','Rc') and ash_leyen ilike '%banco%' order by 1;
select * from astoh where ash_fecval between '01-06-2015' and '30-06-2015' and codcomp(ash_comprob) not in ('AD','FA','FB','CA','RC','Rc') and ash_leyen ilike '%banco%' order by 1;
select sum(astc_importe)::numeric(15,2) from astoctas,compra where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa=0; 
select sum(astc_importe)::numeric(15,2) from astoctas,compra where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa is null; 
select sum(astc_importe)::numeric(15,2) from astoctas,compra where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa is null and astc_importe>0; 
select sum(astc_importe)::numeric(15,2) from astoctas,compra where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa=0 and astc_importe>0; 
select astc_id from astoctas,compra where astc_id not in (select astc_id from astoctas where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_tasa=0 and astc_importe>0) and astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa=0 and astc_importe>0; 
select astc_id from astoctas,compra where astc_id not in (select astc_id from astoctas where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_tasa=0) and astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa=0 and astc_importe>0; 
select astc_id from astoctas,compra where astc_id not in (select astc_id from astoctas where astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_tasa=0 and astc_importe>0) and astc_codemp=1 and astc_ctacble not in (40,39,31,32,26,134) and date_part('year',astc_fecval)=2015 and date_part('month',astc_fecval)=05 and astc_estado=2 and astc_idastoh=cpra_idastoh and astc_tasa=0; 
select * from astoctas where astc_id in (976764,977054);
select * from astoh where ash_id in (314601,314696);
select astc_id,astc_numero,codcomp(astc_comprob),astc_importe,desccble(astc_ctacble) from astoctas where astc_idastoh = 314601;
update astoctas set astc_tasa=null where astc_id=976764;
select astc_id,astc_numero,codcomp(astc_comprob),astc_importe,desccble(astc_ctacble) from astoctas where astc_idastoh = 977054;
select astc_id,astc_numero,codcomp(astc_comprob),astc_importe,desccble(astc_ctacble) from astoctas where astc_idastoh = 314696;
update astoctas set astc_tasa=null where astc_id=977054;
select * from contratos where contr_id=20079:
;
select * from contratos where contr_id=20079;
select * from astoctas where astc_id=959102;
select * from astoctas where astc_id=959102;
