Advertisement
Guest User

Untitled

a guest
May 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. create or replace package body pk_puntos as
  2.  
  3. procedure P_Calcular_Puntos (id_ticket number, cliente varchar2) as
  4. v_total number;
  5. begin
  6.  
  7. select sum(p.precio_actual * d.cantidad) into v_total
  8. from ticket t join detalle d on d.ticket = t.id join producto p on p.codigo_barras = d.producto
  9. where t.id = id_ticket;
  10. update ticket set total = v_total where id = id_ticket;
  11. if cliente is not null then
  12. update ticket set fidelizado = cliente, puntos = trunc (v_total/10) where id = id_ticket;
  13. update fidelizado set puntos_acumulados = puntos_acumulados + trunc (v_total/10) where dni = cliente;
  14. end if;
  15.  
  16. end P_Calcular_Puntos;
  17.  
  18. procedure P_Aplicar_Puntos (id_ticket number, cliente varchar2) as
  19. v_total number;
  20. v_puntos_cliente number;
  21. v_nuevos_puntos number;
  22. v_nuevo_total number;
  23. begin
  24.  
  25. select puntos_acumulados into v_puntos_cliente from fidelizado where dni = cliente;
  26. select total into v_total from ticket where id = id_ticket;
  27. if v_puntos_cliente / 100 <= v_total then
  28. v_nuevos_puntos := 0;
  29. v_nuevo_total := v_total - trunc (v_puntos_cliente / 100);
  30. else
  31. v_nuevo_total := 0;
  32. v_nuevos_puntos := v_puntos_cliente - (v_total*100);
  33. end if;
  34.  
  35. update ticket set total = v_nuevo_total where id = id_ticket;
  36. update fidelizado set puntos_acumulados = v_nuevos_puntos where dni = cliente;
  37.  
  38. end P_Aplicar_Puntos;
  39.  
  40. end pk_puntos;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement