Advertisement
ILyaCyclone

CabinetContracts StageReceiptView

Jul 10th, 2019
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. /* CabinetContracts StageReceiptView */
  2.  
  3. WITH div AS
  4. (
  5. SELECT sf.id_d
  6. , MAX(ac.d_start) d_start
  7. FROM accounts_contract_ ac
  8. , stages_ st
  9. , contract_sources_ cs
  10. , source_financing_ sf
  11. WHERE ac.id_stage = :Bind_IdStage
  12. AND ac.id_stage = st.id_stage
  13. AND st.id_contract = cs.id_contract
  14. AND ac.d_start BETWEEN cs.d_start AND nvl(cs.d_end, ac.d_start)
  15. AND cs.id_source = sf.id_source
  16. GROUP BY sf.id_d
  17. )
  18. , sb AS(
  19. SELECT s.idd_main AS id_d
  20. FROM
  21. (
  22. SELECT s.idd_main, s.idd_subordinate
  23. FROM subordination_ s
  24. WHERE sysdate BETWEEN s.d_start AND nvl(s.d_end, sysdate)
  25. ) s
  26. START WITH s.idd_subordinate
  27. IN
  28. (
  29. SELECT div.id_d
  30. FROM div
  31. )
  32. CONNECT BY prior decode(s.idd_main, s.idd_subordinate, NULL, s.idd_main) = s.idd_subordinate
  33.  
  34. UNION
  35. SELECT id_d
  36. FROM div
  37. )
  38. , org AS(
  39. SELECT o.id_contractor
  40. FROM organizations_ o
  41. , sb
  42. , division_ d
  43. WHERE sb.id_d = d.id_d
  44. AND d.id_contractor = o.id_contractor
  45. )
  46.  
  47. SELECT ac.d_start || '-' || ac.d_end AS DISPLAY
  48. , CASE
  49. WHEN EXISTS
  50. -- свой счёт у филиалов - по старой форме!
  51. (
  52. SELECT 'x'
  53. FROM accounts_ a
  54. , org
  55. , organizations_ o
  56. WHERE a.id_contractor = org.id_contractor
  57. AND org.id_contractor = o.id_contractor
  58. AND o.id_organization <> p_environment_.get_ve_us_text(555)
  59. AND sysdate between a.d_start and nvl(a.d_end, sysdate)
  60. )
  61. THEN to_char(wpms_env_wp.get_property('common.org.app_server_url'))||'/report/generate?_id=receipt-education&'||'id_order='
  62. || p.id_order||'&'||'_filename='||'Направление на оплату договора ' ||REPLACE(ps.Status_Text, '/', '-')
  63.  
  64. WHEN p.idk_order = 62 THEN
  65. to_char(wpms_env_wp.get_property('common.org.app_server_url'))||'/report/generate?_id=receipt-education-moscow&'||'id_order='
  66. || p.id_order||'&'||'_filename='||'Направление на оплату договора ' ||REPLACE(ps.Status_Text, '/', '-')
  67.  
  68. WHEN p.idk_order = 431 THEN
  69. /*
  70. to_char(wpms_env_wp.get_property('common.org.portal_url'))||'/rs/Направление на оплату договора ' || REPLACE(ps.Status_Text, '/', '-')
  71. || '.pdf?cd=1&'||'id_list=' || p.id_order
  72. */
  73. to_char(wpms_env_wp.get_property('common.org.app_server_url'))||'/report/generate?_id=receipt-education-tcb&'||'id_paragraph='
  74. || p.id_paragraph||'&'||'_filename='||'Направление на оплату договора ' ||REPLACE(ps.Status_Text, '/', '-')
  75. END AS LINK
  76.  
  77. , st.id_stage
  78.  
  79. FROM accounts_contract_ ac
  80. , paragraphs_ p
  81. , stages_ st
  82. , contracts_ c
  83. , paragraphs_status_ ps
  84.  
  85. WHERE ac.id_stage = :Bind_IdStage AND
  86. st.id_stage = ac.id_stage
  87. AND ac.id_paragraph = p.id_paragraph
  88. AND p.idk_order IN (62, 431)
  89. AND ac.money > 0
  90. AND st.id_contract = c.id_contract
  91. AND c.id_paragraph = ps.id_paragraph
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement