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