summaryrefslogtreecommitdiff
path: root/sql/fixes/ar_ap_summary_fix_1.2.14.sql
blob: e1c11d8dd09e00660eb5d3cfaf8b3a00b9183ec8 (plain)
  1. BEGIN;
  2. UPDATE ap
  3. SET netamount =
  4. CASE WHEN amount > 0 THEN -1 *
  5. (select sum(amount) from acc_trans
  6. where trans_id = ap.id
  7. AND ((chart_id IN (select id from chart where link = 'AP')
  8. AND amount > 0)
  9. OR (chart_id IN
  10. (select id from chart where link like '%tax%')
  11. )
  12. )
  13. )
  14. ELSE
  15. (select sum(amount) from acc_trans
  16. where trans_id = ap.id
  17. AND ((chart_id IN
  18. (select id from chart where link = 'AP')
  19. AND amount < 0)
  20. OR (chart_id IN
  21. (select id from chart
  22. where link like '%tax%')
  23. )
  24. )
  25. )
  26. END
  27. WHERE netamount IS NULL;
  28. update ap set datepaid = NULL where paid = 0;
  29. UPDATE ar
  30. SET netamount =
  31. CASE WHEN amount > 0 THEN -1 *
  32. (select sum(amount) from acc_trans
  33. where trans_id = ar.id
  34. AND ((chart_id IN
  35. (select id from chart where link = 'AR')
  36. AND amount < 0)
  37. OR (chart_id IN
  38. (select id from chart
  39. where link like '%tax%')
  40. )
  41. )
  42. )
  43. ELSE -1 *
  44. (select sum(amount) from acc_trans
  45. where trans_id = ar.id
  46. AND ((chart_id IN (select id from chart
  47. where link = 'AR')
  48. AND amount > 0)
  49. OR (chart_id IN
  50. (select id from chart where link like '%tax%')
  51. )
  52. )
  53. )
  54. END
  55. WHERE netamount IS NULL;
  56. update ar set datepaid = NULL where paid = 0;
  57. commit;