Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace package body pk_puntos as
- procedure P_Calcular_Puntos (id_ticket number, cliente varchar2) as
- v_total number;
- begin
- select sum(p.precio_actual * d.cantidad) into v_total
- from ticket t join detalle d on d.ticket = t.id join producto p on p.codigo_barras = d.producto
- where t.id = id_ticket;
- update ticket set total = v_total where id = id_ticket;
- if cliente is not null then
- update ticket set fidelizado = cliente, puntos = trunc (v_total/10) where id = id_ticket;
- update fidelizado set puntos_acumulados = puntos_acumulados + trunc (v_total/10) where dni = cliente;
- end if;
- end P_Calcular_Puntos;
- procedure P_Aplicar_Puntos (id_ticket number, cliente varchar2) as
- v_total number;
- v_puntos_cliente number;
- v_nuevos_puntos number;
- v_nuevo_total number;
- begin
- select puntos_acumulados into v_puntos_cliente from fidelizado where dni = cliente;
- select total into v_total from ticket where id = id_ticket;
- if v_puntos_cliente / 100 <= v_total then
- v_nuevos_puntos := 0;
- v_nuevo_total := v_total - trunc (v_puntos_cliente / 100);
- else
- v_nuevo_total := 0;
- v_nuevos_puntos := v_puntos_cliente - (v_total*100);
- end if;
- update ticket set total = v_nuevo_total where id = id_ticket;
- update fidelizado set puntos_acumulados = v_nuevos_puntos where dni = cliente;
- end P_Aplicar_Puntos;
- end pk_puntos;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement