Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. SELECT
  2. *,
  3. (UNKANDDOCADJ + OSV) AS Adjustment,
  4. (
  5. Amount - OSV - UNKANDDOCADJ - Payment
  6. ) AS Outstanding
  7. FROM
  8. (
  9. SELECT
  10. t4060r001 AS RecordID,
  11. t4060r002 AS RecordTimestamp,
  12. t4060r003 AS RecordStatus,
  13. 'SLIV-L' AS DocumentType,
  14. t4060f002 AS DocumentNo,
  15. t4060f003 AS DocumentDate,
  16. t4060f005 AS AgreementNo,
  17. t4060f006 AS HirerID,
  18. t4060f007 AS HirerName,
  19. sum(t4061f009) AS Amount,
  20. IFNULL(
  21. (
  22. SELECT
  23. sum(vAmount)
  24. FROM
  25. vpaymenttrans
  26. WHERE
  27. vInv = t4060f002
  28. AND vHA = t4060f005
  29. AND vDate <= '2019-06-30 23:59:59'
  30. AND vTipe IN (
  31. 'DOCUMENT ADJUSTMENT',
  32. 'SALES CREDIT NOTE'
  33. )
  34. ),
  35. 0
  36. ) AS UNKANDDOCADJ,
  37. IFNULL(
  38. (
  39. SELECT
  40. sum(t4075f005)
  41. FROM
  42. t4075
  43. LEFT JOIN t4074 ON t4074.t4074r001 = t4075.t4075f001
  44. WHERE
  45. t4074r003 = 1
  46. and t4075f003 = t4060f002
  47. AND t4074f006 = t4060f006
  48. and t4074f003 <= '2019-06-30 23:59:59'
  49. ),
  50. 0
  51. ) AS OSV,
  52. IFNULL(
  53. (
  54. SELECT
  55. sum(t4081f006)
  56. FROM
  57. t4081
  58. LEFT JOIN t4080 ON t4080.t4080r001 = t4081.t4081f001
  59. WHERE
  60. t4080r003 = 1
  61. and t4081f003 = t4060f002
  62. AND t4080f006 = t4060f006
  63. and t4080f003 <= '2019-06-30 23:59:59'
  64. ),
  65. 0
  66. ) AS Payment
  67. from
  68. t4060
  69. LEFT JOIN t4061 on t4061f001 = t4060r001
  70. WHERE
  71. t4060r003 = 1
  72. AND t4060f003 BETWEEN '0001-01-01 00:00:00'
  73. AND '2019-06-30 23:59:59'
  74. AND t4060f012 != 0
  75. AND t4060f001 = 'SLIV-L'
  76. Group By
  77. t4060r001
  78. ) as X
  79. Having
  80. Outstanding > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement