This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.encode(val character varying) | |
RETURNS character varying AS | |
$BODY$ | |
BEGIN | |
RETURN encode(digest(val, 'sha1'), 'hex')::character varying; | |
END; | |
$BODY$ | |
LANGUAGE plpgsql VOLATILE | |
COST 100; | |
ALTER FUNCTION public.encode(character varying) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION get_fecha_vencimiento() | |
RETURNS DATE AS $$ | |
DECLARE | |
dia_ven integer; | |
today integer; | |
result date; | |
BEGIN | |
SELECT c.dia_vencimiento INTO dia_ven FROM config c LIMIT 1; | |
IF (dia_ven IS NULL) THEN | |
RAISE EXCEPTION 'Error grave: no existe dia de vencimiento en la tabla de configuración'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.get_fecha_emision() | |
RETURNS date AS | |
$BODY$ | |
DECLARE | |
dia_em integer; | |
today integer; | |
result date; | |
BEGIN | |
SELECT c.dia_emision INTO dia_em FROM config c LIMIT 1; | |
IF (dia_em IS NULL) THEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION compare_fecha_hoy(fecha date) | |
RETURNS BOOLEAN AS $$ | |
DECLARE | |
BEGIN | |
IF (fecha > now()::date) THEN | |
RETURN TRUE; | |
ELSE | |
RETURN FALSE; | |
END IF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE USER username WITH PASSWORD 'password'; | |
GRANT SELECT, INSERT, UPDATE, DELETE | |
ON ALL TABLES IN SCHEMA public | |
TO user_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.validate_cuit(cuit character varying) | |
RETURNS boolean AS | |
$BODY$ | |
DECLARE | |
cuit_array text[]; | |
serie integer[]; | |
aux integer; | |
result boolean; | |
BEGIN | |
result = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean validate(String cuit){ | |
//Eliminamos todos los caracteres que no son números | |
cuit = cuit.replaceAll("[^\\d]", ""); | |
//Controlamos si son 11 números los que quedaron, si no es el caso, ya devuelve falso | |
if (cuit.length() != 11){ | |
return false; | |
} | |
//Convertimos la cadena que quedó en una matriz de caracteres | |
String[] cuitArray = cuit.split(""); | |
//Inicializamos una matriz por la cual se multiplicarán cada uno de los dígitos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Genero { | |
MASCULINO,FEMENINO,SOCIEDAD | |
} | |
public static String generate(Genero g,int dni) throws Exception{ | |
int tipo; | |
if (g.equals(Genero.MASCULINO)) { | |
tipo = 20; | |
} | |
else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function random_string(length integer) returns text as | |
$$ | |
declare | |
chars text[] := '{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}'; | |
result text := ''; | |
i integer := 0; | |
begin | |
if length < 0 then | |
raise exception 'Given length cannot be less than 0'; | |
end if; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void PDF(Map<String,Object> params, String jasperPath, List<?> dataSource,String fileName) throws JRException, IOException{ | |
String relativeWebPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath(jasperPath); | |
File file = new File(relativeWebPath); | |
JRBeanCollectionDataSource source = new JRBeanCollectionDataSource(dataSource); | |
JasperPrint print = JasperFillManager.fillReport(file.getPath(), params, source); | |
HttpServletResponse response = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse(); | |
response.addHeader("Content-disposition", "attachment;filename=" + fileName); | |
ServletOutputStream stream = response.getOutputStream(); | |
JasperExportManager.exportReportToPdfStream(print,stream); |