opportunity.storage.factory.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. angular.module('odoo')
  2. .factory('opportunitiesStorageFactory', function () {
  3. var save = function (opportunity, success, error) {
  4. var values = [
  5. opportunity.remote_id ? opportunity.remote_id : 0,
  6. 1,
  7. opportunity.name ? opportunity.name : '',
  8. opportunity.description ? opportunity.description : '',
  9. opportunity.contact_name ? opportunity.contact_name : '',
  10. opportunity.phone ? opportunity.phone : '',
  11. opportunity.mobile ? opportunity.mobile : '',
  12. opportunity.fax ? opportunity.fax : '',
  13. opportunity.street ? opportunity.street : '',
  14. opportunity.street2 ? opportunity.street2 : '',
  15. opportunity.meeting_count ? opportunity.meeting_count : 0,
  16. opportunity.message_bounce ? opportunity.message_bounce : 0,
  17. opportunity.planned_cost ? opportunity.planned_cost : 0,
  18. opportunity.planned_revenue ? opportunity.planned_revenue : 0,
  19. opportunity.priority ? opportunity.priority : 2,
  20. opportunity.probability ? opportunity.probability : 0,
  21. (opportunity.type == undefined || opportunity.type == 'lead') ? 'opportunity' : opportunity.type,
  22. opportunity.partner_id ? opportunity.partner_id : 0
  23. ];
  24. var sql = null;
  25. if (opportunity.id) {
  26. values.push(opportunity.id);
  27. sql = 'UPDATE lead SET ' +
  28. 'remote_id = ?,' +
  29. 'modified = ?,' +
  30. 'modifiedDate = CURRENT_TIMESTAMP,' +
  31. 'name = ?,' +
  32. 'description = ?,' +
  33. 'contact_name = ?,' +
  34. 'phone = ?,' +
  35. 'mobile = ?,' +
  36. 'fax = ?,' +
  37. 'street = ?,' +
  38. 'street2 = ?,' +
  39. 'meeting_count = ?,' +
  40. 'message_bounce = ?,' +
  41. 'planned_cost = ?,' +
  42. 'planned_revenue = ?,' +
  43. 'priority = ?,' +
  44. 'probability = ?,' +
  45. 'type = ?,' +
  46. 'partner_id = ? ' +
  47. 'WHERE id = ?';
  48. } else {
  49. sql = 'INSERT INTO lead(' +
  50. 'remote_id,' +
  51. 'modified,' +
  52. 'name,' +
  53. 'description,' +
  54. 'contact_name,' +
  55. 'phone,' +
  56. 'mobile,' +
  57. 'fax,' +
  58. 'street,' +
  59. 'street2,' +
  60. 'meeting_count,' +
  61. 'message_bounce,' +
  62. 'planned_cost,' +
  63. 'planned_revenue,' +
  64. 'priority,' +
  65. 'probability,' +
  66. 'type,' +
  67. 'partner_id) ' +
  68. 'VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
  69. }
  70. db.executeSql(sql, values, function (result) {
  71. success(sql.startsWith('INSERT') ? result.insertId : opportunity.id);
  72. }, function (err) {
  73. error(err);
  74. });
  75. }
  76. // Remove opportunity from local storage
  77. var remove = function (opportunity, success, error) {
  78. var values = [opportunity.id];
  79. var sql = null;
  80. if (opportunity.remote_id) {
  81. sql = 'UPDATE lead SET modified = 2 WHERE id = ?';
  82. } else {
  83. sql = 'DELETE FROM lead WHERE id = ?'
  84. }
  85. db.executeSql(sql, values, function (result) {
  86. success(result.rowsAffected);
  87. }, function(err) {
  88. error(err);
  89. });
  90. }
  91. var removeAll = function (success, error) {
  92. var sql = "DELETE FROM lead WHERE type = 'opportunity'";
  93. db.executeSql(sql, [], function(result) {
  94. success(result.rowsAffected);
  95. }, function(err) {
  96. error(err);
  97. });
  98. }
  99. return {
  100. save: save,
  101. remove: remove,
  102. removeAll: removeAll
  103. }
  104. });