select * from empresa;
delete from subxcomp;
\h subxcomp
\d subxcomp
\d comprob
select * from emleados;
select * from empleados;
delete from empleados;
select * from sucursalc,clientes where cli_codemp!=5 and cli_id=sucu_cliente;
select * from sucursalc;
select count(*) from sucursalc;
select count(*) from clientes;
select count(*) from clientes where cli_codemp!=5;
select cargo_articu_receta(5);
select cargo_articu_receta(5);
select cargo_articu_receta(5);
select cargo_articu_receta(5);
select * from receta;
select * from articu where artc_id=1600;
select * from articvta where art_id=9416;
\d
select * from subd;
select * from subxcomp;
select * from cheques;;
\d talon
select * from talon;
select * from stock;
select * from movsleyen;
select * from movsto;
select * from movstoc;
select * from compra;
select * from stock;
select * from astoh;
select * from astoh order by 1 desc limit 4;
\d+ astoh
\d+ astoh_ash_id_seq
select * from astoh order by 1 desc limit 4;
select * from astoctas where astc_leyen='Deposito 181/09/2015';
update astoctas set astc_leyen='Deposito 18/09/2015' where astc_leyen='Deposito 181/09/2015';
select * frrom astoctas where astc_idastoh=9068;
select * from astoctas where astc_idastoh=9058;
select * from ctacble where cbl_codigo=1201;
select * from ctacble where cbl_codigo='1201';
select astc_ctacte,sum(astc_importe) from astoctas where astc_ctacble=4818 and astc_tipcta!=99 group by 1;
select astc_ctacte,sum(astc_importe) from astoctas where astc_ctacble=4818 and astc_tipcta=99 group by 1;
select * from astoctas where astc_idastoh=9058 limit 1;
insert into astoctas (astc_idastoh,astc_ctacble,astc_tipcta,astc_estado,astc_codemp,astc_idptov,astc_comprob,astc_numero,astc_fecval,astc_moneda,astc_ctacte,astc_importe) select 9058,4818,99,-1,5,42,578,1,'18-09-2015',1,astc_ctacte,sum(astc_importe)*-1 from astoctas where astc_ctacble=4818 and astc_tipcta=99 group by 1,2,3,4,5,6,7,8,9,10,11;
insert into astoctas (astc_idastoh,astc_ctacble,astc_tipcta,astc_estado,astc_codemp,astc_idptov,astc_comprob,astc_numero,astc_fecval,astc_moneda,astc_ctacte,astc_importe) select 9058,4818,99,-1,5,42,578,1,date(now()),1,astc_ctacte,sum(astc_importe)*-1 from astoctas where astc_ctacble=4818 and astc_tipcta=99 group by 1,2,3,4,5,6,7,8,9,10,11;
select * from astoctas where astc_idastoh=9058 and astc_ctacble=4818;
update astoctas set astc_fecval='18-09-2015' where astc_idastoh=9058 and astc_ctacble=4818;
select astc_ctacte,sum(astc_importe) from astoctas where astc_ctacble=4818 and astc_tipcta=99 group by 1;
select astc_cierra from astoctas where astc_ctacble=4818 and astc_tipcta=99;
update astoctas set astc_cierra=2 where astc_ctacble=4818 and astc_tipcta=99;
select astc_ctacte,sum(astc_importe) from astoctas where  astc_tipcta=98 group by 1;
select astc_ctacte,sum(astc_importe) from astoctas where  astc_tipcta=99 group by 1 having sum(astc_importe)!=0;
select * from astoh where ash_id=9058;
update astoh set ash_fecomp='19-09-2015', ash_fecval='19-09-2015' where ash_id=9058;
select * from astoctas where astc_idastoh=9058 and astc_ctacble=4818;
select astc_ctacte,sum(astc_importe) from astoctas where  astc_tipcta=99 and astc_estado=2 group by 1 having sum(astc_importe)!=0;
update astoh set astc_importe=astc_importe+183,50 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1383;
update astoh set astc_importe=astc_importe+183.50 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1383;
update astoctas set astc_importe=astc_importe+183.50 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1383;
select astc_ctacte,sum(astc_importe) from astoctas where  astc_tipcta=99 and astc_estado=2 group by 1 having sum(astc_importe)!=0;
update astoctas set astc_importe=astc_importe+95.24 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1922;
update astoctas set astc_importe=astc_importe+128.53 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1309;
update astoctas set astc_importe=astc_importe+10784.18 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1374;
select astc_ctacte,sum(astc_importe) from astoctas where  astc_tipcta=99 and astc_estado=2 group by 1 having sum(astc_importe)!=0;
update astoctas set astc_importe=astc_importe+0.7 where astc_idastoh=9058 and astc_tipcta=99 and astc_ctacte=1922;
select astc_ctacte,sum(astc_importe) from astoctas where  astc_tipcta=99 and astc_estado=2 group by 1 having sum(astc_importe)!=0;
select * from astoctas limit 1; 
select * from astoh order by 1 desc;
delete from astoh where ash_id=9079;
delete from astoh where ash_id=9080;
select * from astoh order by 1 desc;
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select codcli(astc_ctacte),astc_grupo,sum(astc_importe),count(*) from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=2 and astc_idastoh<=9058 group by 1,2 having count(*)>1;
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select codcli(astc_ctacte),astc_grupo,sum(astc_importe),count(*) from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=2 and astc_idastoh<=9058 group by 1,2 having count(*)>1;
select codcli(astc_ctacte),astc_ctacte,astc_grupo,sum(astc_importe),count(*) from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=2 and astc_idastoh<=9058 group by 1,2 having count(*)>1;
select codcli(astc_ctacte),astc_ctacte,astc_grupo,sum(astc_importe),count(*) from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=2 and astc_idastoh<=9058 group by 1,2,3 having count(*)>1;
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select arrecta(5,4818,99);
select codcli(astc_ctacte),astc_ctacte,astc_grupo,astc_importe from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=100;
update astoctas set astc_cierra=1,astc_grupo=8 where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=100 and astc_importe=93.17;
update astoctas set astc_cierra=1 where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=100;
update astoctas set astc_cierra=2 where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=1 and astc_grupo=-3;
select arrecta(5,4818,99);
select codcli(astc_ctacte),astc_ctacte,astc_grupo,astc_importe from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and astc_cierra=100;
select codcli(astc_ctacte),astc_ctacte,astc_grupo,astc_importe from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and codcli(astc_ctacte)='CA006';
select codcli(astc_ctacte),astc_ctacte,astc_grupo,astc_importe,astc_cierra from astoctas where astc_codemp=5 and astc_estado=2 and astc_ctacble=4818 and astc_tipcta=99 and codcli(astc_ctacte)='CA006';
select * from pxarticu;
select * from pxarticu order by 1 desc;
select * from pxarticu order by 1 desc;
select * from listpre order by 1 desc;
select * from articvta where art_id=10271;
select * from listpre where ltp_idart=10271 order by 1;
select * from pxarticu order by 1 desc;
select * from pxarticu order by 1 desc;
select * from pxarticu order by 1 desc;
select * from pxarticu order by 1 desc;
select * from pxarticu where pxa_estado=3 order by 1 desc;
select * from listpre where ltp_nrolista=8;
select * from listpre where ltp_nrolista=8 order by 1 desc;
select * from listpre where ltp_nrolista=1 order by 1 desc;
select * from listpre where ltp_nrolista=1 order by 1 desc;
select * from listpre where ltp_nrolista=8 order by 1 desc;
select ltp_idart,ltp_nrolista,count(*) from listpre where ltp_estado=1 and ltp_idcli is null group by 1,2 having count(*)>1;
select * from astoctas where astc_ctacble=4479;
update astoctas set astc_ctacble=4779 where astc_ctacble=4479;
select * from articvta where art_codcbl = 4479;
update articvta  set art_codcbl = 4779,art_idcbl = 4779 where art_idcbl=4479;
update articvta  set art_codcbl = 4779,art_idcbl = 4779 where art_codcbl=4479;
select * from listpre where ltp_nrolista=8 order by 1 desc;
select * from astoh where ash_id=41521;
select * from astoctas where astc_idastoh=41521;
select * from astoctas where astc_id=127574;
select * from modlogs where log_tabla='astoctas' and log_idtabla=127574;
update astoh set ash_estado=-1 where ash_id=41521;
select * from cheques where chq_idastoc=127573;
update cheques set chq_idastoce=128508,chq_estado=3 where chq_id=5799;
