Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. \echo Post-Hook SQL Scripts - Run after new events have been created.
  2.  
  3. begin;
  4.  
  5. \echo Summary of events for event_def=105
  6. select state,count(id) from action_trigger.event where event_def=105 group by state;
  7.  
  8. \echo Change event to invalid if phone notify not set.
  9. -- Set to invalid if phone notify not set.
  10. UPDATE action_trigger.event ate
  11. set state='invalid'
  12. from action.hold_request ahr
  13. where
  14. ahr.id=ate.target
  15. and ate.event_def=105
  16. and ate.state='pending'
  17. and ahr.phone_notify is null
  18. ;
  19.  
  20. \echo Change event to invalid if hold has been fulfilled.
  21. UPDATE action_trigger.event ate
  22. set state='invalid'
  23. from action.hold_request ahr
  24. where
  25. ahr.id=ate.target
  26. and ate.event_def=105
  27. and ate.state='pending'
  28. and ahr.fulfillment_time is not null
  29. ;
  30.  
  31. \echo Change event to pending-delay if call has been sent for this customer in last 12 hours.
  32. UPDATE action_trigger.event ate
  33. set state='invalid',user_data='{"state": "pending-delay"}'::json
  34. from action.hold_request ahr
  35. where
  36. ahr.id=ate.target
  37. and ate.event_def=105
  38. and ate.state='pending'
  39. and exists (
  40. select 1
  41. from action_trigger.event ates
  42. join action.hold_request ahrs on ates.target=ahrs.id
  43. where
  44. ates.event_def=105
  45. and ates.state='complete'
  46. and ates.update_time > now()-'12 hours'::interval
  47. and ahrs.usr=ahr.usr
  48. )
  49. returning ate.id eventid, ahr.usr userid, ahr.id holdid
  50. ;
  51.  
  52. \echo Summary of events for event_def=105 - After changes.
  53. select state,count(id) from action_trigger.event where event_def=105 group by state;
  54.  
  55. \echo Summary of phone calls by pickup location
  56. select aou.shortname, count(distinct ahr.usr) as patrons, count(distinct ahr.id) as items
  57. from
  58. action_trigger.event ate
  59. join action.hold_request ahr on ate.target=ahr.id
  60. join actor.org_unit aou on ahr.pickup_lib=aou.id
  61. where
  62. ate.event_def=105
  63. and ate.state='pending'
  64. group by aou.parent_ou, aou.shortname
  65. order by aou.parent_ou, aou.shortname
  66. ;
  67.  
  68. commit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement