modifstoreiuta
TRANSCRIPT
-
8/7/2019 modifStoreIUTA
1/3
/*CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS '/usr/lib/postgresql/8.1/lib/plpgsql.so' LANGUAGE 'C';CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL';*/
--drop table actualizaepw;
CREATE TABLE actualizaepw(nroregistro_epw integer,nropersona integer,tippin character varying,codpin character varying,codestacad character varying,codcarrera character varying,codestudiante character varying,nombrecompleto character varying,descrestacad character varying,descrcarrera character varying,
fechanacmto character varying,lugarnacmto character varying,direcchabitacion1 character varying,direcchabitacion2 character varying,direcchabitacion3 character varying,direcchabitacion4 character varying,codpostalhabitac character varying,ciudadhabitac character varying,correoelectronico character varying,estudianteactivo character varying
);
CREATE TABLE actualizaefw(nroRegistro_EFW integer,nroPersona integer,tipPin character varying,codPin character varying,codEstAcad character varying,codCarrera character varying,codEstudiante character varying,nroFactura character varying,origen character varying,fechaEmision character varying,fechaVencmto character varying,monto numeric (18,2),
codConcepto character varying,codSubConcepto character varying,descrConcepto character varying,descrSubConcepto character varying,refPago character varying,fechaPago character varying
);
--drop function importaDataCampusA2(ruta character varying, archivo character varying)CREATE OR REPLACE FUNCTION importadatacampusa2(ruta character varying, archivo character varying)
RETURNS void AS
-
8/7/2019 modifStoreIUTA
2/3
$BODY$declare
sentencia varchar;reg_archivo record;reg_aepw record;reg_aefw record;nroRegPW integer := 0;nroRegFW integer := 0;nroepw integer;
begin
if archivo = 'EstudiantesParaPagosWeb.txt' thendelete from actualizaepw;sentencia := 'copy actualizaepw from ' '''' ruta archivo
'''' ' delimiters ' ''' ''';execute sentencia;
for reg_archivo inselect * from actualizaepw
loop select * into reg_aepw from estudiantesparapagosweb epwwhere
epw.ciaopr = '1'and epw.nropersona = reg_archivo.nropersonaand epw.tippin = reg_archivo.tippinand epw.codpin = reg_archivo.codpinand epw.codestacad = reg_archivo.codestacadand epw.codcarrera = reg_archivo.codcarreraand epw.codestudiante = reg_archivo.codestudiant
e;
if not found thennroRegPW := nroRegPW +1;insert into estudiantesparapagosweb (ciaopr,nror
egistro_epw,nropersona,tippin,codpin,codestacad,codcarrera,codestudiante,nombrecompleto,
descrestacad,descrcarrera,fechanacmto,lugarnacmto,direcchabitacion1,direcchabitacion2,dire
cchabitacion3,direcchabitacion4,codpostalhabitac,ciudadhabitac,correoelectronico,estudian
teactivo)values('1',nroRegPW,reg_archivo.nropersona,reg_a
rchivo.tippin,reg_archivo.codpin,reg_archivo.codestacad,reg_archivo.codca
rrera,reg_archivo.codestudiante,reg_archivo.nombrecompleto,reg_archivo.descrestacad,reg_archivo.des
crcarrera,reg_archivo.fechanacmto,reg_archivo.lugarnacmto,reg_archivo.direcchabitacion1,reg_archiv
o.direcchabitacion2,reg_archivo.direcchabitacion3,reg_archivo.direcchabitacion4,reg_archiv
o.codpostalhabitac,reg_archivo.ciudadhabitac,reg_archivo.correoelectronico,reg_archiv
o.estudianteactivo);end if;
end loop;end if;
if archivo = 'EstudiantesFacturasWeb.txt' thendelete from actualizaefw;sentencia := 'copy actualizaefw from ' '''' ruta archivo
-
8/7/2019 modifStoreIUTA
3/3
'''' ' delimiters ' ''' ''';execute sentencia;
for reg_archivo inselect * from actualizaefw
loopselect * into reg_aefw from estudiantesfacturasweb efw w
hereefw.ciaopr = '1'and efw.nrofactura = reg_archivo.nrofactura;
if not found thenselect nroregistro_epw into nroepw from estudian
tesparapagosweb epwwhere epw.ciaopr = '1'and epw.nropersona = reg_archivo.nropers
onaand epw.tippin = reg_archivo.tippinand epw.codpin = reg_archivo.codpinand epw.codestacad = reg_archivo.codesta
cad and epw.codcarrera = reg_archivo.codcarrera
and epw.codestudiante = reg_archivo.codestudiante;
if not found thenraise notice 'No encontre nada';--Debo informar que hay facturas
que no poseen estudiantes registradoselse
nroRegFW := nroRegFW +1;insert into estudiantesfacturasw
eb (ciaopr,nroregistro_epw,nroregistro_efw,nropersona,tippin,codpin,codestacad,codcarrera,co
destudiante,nrofactura,origen,fechaemision,fechavencmto,monto,codconcepto,codsubconcep
to,descrconcepto,descrsubconcepto,refpago,fechapago)values ('1',nroepw,nroRegFW,reg_
archivo.nropersona,reg_archivo.tippin,reg_archivo.codpin,reg_archivo.codestacad,r
eg_archivo.codcarrera,reg_archivo.codestudiante,reg_archivo.nrofactura,reg_archivo.origen,reg_a
rchivo.fechaemision,reg_archivo.fechavencmto,reg_archivo.monto,reg_archivo.codconcepto,
reg_archivo.codsubconcepto,reg_archivo.descrconcepto,reg_archivo.descrsubconc
epto,reg_archivo.refpago,reg_archivo.fechapago);end if;
end if;end loop;
end if;
end; $BODY$LANGUAGE 'plpgsql' VOLATILE STRICT SECURITY DEFINER;