select * from empresas;
select * from operadores;
select * from empresa;
select * from empresa;
select * from ctacble where cbl_id=1771;
select * from ctacble where cbl_id=1770;
update ctacble set cbl_codigo=2229 where cbl_id=1770;
select * from astoctas where astc_idastoh=11166;L
select * from astoctas where astc_idastoh=11166;
select * from astoctas where astc_idastoh=11166;
select * from ptovta;
select * from astoctas where astc_idastoh=11167;
select * from astoh where ash_id=11167;
select * from astoctas where ast_idastoh=11533;
select * from astoctas where astc_idastoh=11533;
select * from ptovta where ptv_id in (4,5,38);
insert into astoctas (astc_idastoh,astc_codemp,astc_idptov,astc_comprob,astc_numero,astc_fecval,astc_ctacble,astc_importe,astc_moneda,astc_valor,astc_estado,astc_tasa) values (11163,2,4,263,181,'10-05-2015',1756,-450000::numeric,1,0::numeric,-1,); 
insert into astoctas (astc_idastoh,astc_codemp,astc_idptov,astc_comprob,astc_numero,astc_fecval,astc_ctacble,astc_importe,astc_moneda,astc_valor,astc_estado,astc_tasa) values (11163,2,4,263,181,'10-05-2015',1756,-450000::numeric,1,0::numeric,-1,0); 
insert into astoctas (astc_idastoh,astc_codemp,astc_idptov,astc_comprob,astc_numero,astc_fecval,astc_ctacble,astc_importe,astc_moneda,astc_valor,astc_estado,astc_tasa) values (11163,2,4,263,181,'10-05-2015',1652,424613.4::numeric,1,0::numeric,-1,0); 
insert into astoctas (astc_idastoh,astc_codemp,astc_idptov,astc_comprob,astc_numero,astc_fecval,astc_ctacble,astc_importe,astc_moneda,astc_valor,astc_estado,astc_tasa) values (11163,2,4,263,181,'10-05-2015',1775,25386.6::numeric,1,0::numeric,-1,0); 
select * from movstoc limit 1;
select * from movstoc where movc_idptov=4 and movc_fecval<'01-08-215' limit 1;
select * from movstoc where movc_idptov=4 and movc_fecval<'01-08-2015' limit 1;
select nomarticu(movc_artic) from movstoc where movc_idptov=4 and movc_fecval<'01-08-2015' limit 1;
select * from articu;
select artc_nombre from movstoc where artc_id=movc_artic and movc_idptov=4 and movc_fecval<'01-08-2015' limit 1;
select nomarticu(movc_artic) from movstoc,articu where movc_idptov=4 and movc_fecval<'01-08-2015' limit 1;
select artc_nombre from movstoc,articu where artc_id=movc_artic and movc_idptov=4 and movc_fecval<'01-08-2015' limit 1;
select artc_nombre,artc_precio,sum(movc_canti) from movstoc,articu where artc_id=movc_artic and movc_idptov=4 and movc_fecval<'01-08-2015' group by 1,2 order by 1,2;
select * from movstoc where movc_idptov=4 and movc_fecval<'01-08-2015' limit 1;
select artc_nombre,movc_precio,sum(movc_canti) from movstoc,articu where artc_id=movc_artic and movc_idptov=4 and movc_fecval<'01-08-2015' group by 1,2 order by 1,2;
select * from ctacble where cbl_codigo='1015';
select * from empresas;
select * from empresa;
select * from ctacble where cbl_codigo='1015';
select sum(astc_importe) from astoctas where actc_ctacble=1652 and astc_idptov=4 and astc_estado=2;
select sum(astc_importe) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2;
select sum(chq_importe) from cheques where chq_idptov=4 and chq_estado<99;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoc group by 1,2;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoc and (astc_importe-sum(chq_importe))!=0 group by 1,2;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoc group by 1,2 having (astc_importe-sum(chq_importe))!=0;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoc group by 1,2 having (astc_importe+sum(chq_importe))!=0;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoc group by 1,2 having (astc_importe-sum(chq_importe))!=0;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoc and astc_importe>0 group by 1,2 having (astc_importe-sum(chq_importe))!=0;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoce and astc_importe<0 group by 1,2 having (astc_importe-sum(chq_importe))!=0;
select astc_id,astc_importe,sum(chq_importe) from astoctas,cheques where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_id=chq_idastoce and astc_importe<0 group by 1,2 having (astc_importe+sum(chq_importe))!=0;
\df+ chq
select astc_id,astc_importe,totchqastc(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe>0 and (astc_importe-totchqastc(astc_id))!=0;
select astc_id,astc_importe,totchqastc(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe>0 and (astc_importe-totchqastc(astc_id))=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe-totchqastc(astc_id))!=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe+totchqastc(astc_id))!=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe+totchqastc(astc_id))=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 ;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe-totchqastc(astc_id))=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe-totchqastc(astc_id))!=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe-totchqastce(astc_id))!=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe<0 and (astc_importe-totchqastce(astc_id))=0;
select astc_id,astc_importe,totchqastce(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado!=2 and astc_importe<0 and (astc_importe-totchqastce(astc_id))=0;
select astc_id,astc_importe,totchqastc(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe>0 and (astc_importe-totchqastc(astc_id))=0;
select astc_id,astc_importe,totchqastc(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado=2 and astc_importe>0 and (astc_importe+totchqastc(astc_id))=0;
select astc_id,astc_importe,totchqastc(astc_id) from astoctas where astc_ctacble=1652 and astc_idptov=4 and astc_estado!=2 and astc_importe>0 and (astc_importe+totchqastc(astc_id))=0;
select chq_estado,importedeastc(chq_idastoc),sum(chq_importe) from cheques where chq_idptov=4 group by 1,2;
select chq_idastoc,chq_estado,importedeastc(chq_idastoc),sum(chq_importe) from cheques where chq_idptov=4 group by 1,2,3 having (importedeastc(chq_idastoc)-sum(chq_importe))!=0;
select chq_idastoc,chq_estado,importedeastc(chq_idastoc),sum(chq_importe) from cheques where chq_idptov=4 group by 1,2,3 having (importedeastc(chq_idastoc)-sum(chq_importe))!=0 order by 1;
select chq_idastoc,importedeastc(chq_idastoc),sum(chq_importe) from cheques where chq_idptov=4 group by 1,2 having (importedeastc(chq_idastoc)-sum(chq_importe))!=0 order by 1;
select chq_idastoc,importedeastc(chq_idastoc),sum(chq_importe) from cheques where chq_idptov=4 group by 1,2 having (importedeastce(chq_idastoc)-sum(chq_importe))!=0 order by 1;
select chq_idastoc,importedeastc(chq_idastoc),sum(chq_importe) from cheques where chq_idptov=4 group by 1,2 having (importedeastc(chq_idastoc)-sum(chq_importe))!=0 order by 1;
select * from astoh where ash_id=24841;
select * from astoh order by 1 desc;
select * from astoh where ash_numero=1312;
select * from astoctas where astc_idastoh=4437;
select astc_grupo,sum(astc_importe) from astoctas where astc_tipcta=98 and astc_ctacte=160 and astc_cierra=2;
select astc_grupo,sum(astc_importe) from astoctas where astc_tipcta=98 and astc_ctacte=160 and astc_cierra=2 group by 1;
update astoctas set astc_cierra=1 where astc_tipcta=98 and astc_ctacte=160 and astc_cierra=2 and astc_grupo in (77,75,76,74,80,90);
