Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. //create contractEntitlementsAPI following the pattern of api/model/instance for other entities
  2. /**
  3. * Get All contract entitlements for given contact id
  4. Query to fetch data is
  5. CRM.api3('HRJobContract', 'get', {
  6. "sequential": 1,
  7. "contact_id": 206,
  8. "api.HRJobContract.getfulldetails": {"jobcontract_id":"$value.id"}
  9. }).done(function(result) {
  10. // do something
  11. });
  12. will return
  13. {
  14.  
  15. "is_error": 0,
  16. "version": 3,
  17. "count": 1,
  18. "id": 2,
  19. "values": [
  20. {
  21. "id": "2",
  22. "contact_id": "206",
  23. "is_primary": "1",
  24. "deleted": "0",
  25. "is_current": "1",
  26. "api.HRJobContractRevision.get": {
  27. "is_error": 0,
  28. "version": 3,
  29. "count": 1,
  30. "id": 8,
  31. "values": [
  32. {
  33. "id": "8",
  34. "jobcontract_id": "2",
  35. "editor_uid": "1",
  36. "created_date": "2017-03-28 12:08:46",
  37. "effective_date": "2017-03-28",
  38. "modified_date": "2017-03-28 12:08:48",
  39. "details_revision_id": "8",
  40. "health_revision_id": "8",
  41. "hour_revision_id": "8",
  42. "leave_revision_id": "8",
  43. "pay_revision_id": "8",
  44. "pension_revision_id": "8",
  45. "role_revision_id": "8",
  46. "deleted": "0",
  47. "editor_name": "admin@example.com",
  48. "api.HRJobLeave.get": {
  49. "is_error": 0,
  50. "version": 3,
  51. "count": 3,
  52. "values": [
  53. {
  54. "id": "4",
  55. "leave_type": "1",
  56. "leave_amount": "20",
  57. "add_public_holidays": "1",
  58. "jobcontract_revision_id": "8"
  59. },
  60. {
  61. "id": "5",
  62. "leave_type": "2",
  63. "leave_amount": "10",
  64. "add_public_holidays": "0",
  65. "jobcontract_revision_id": "8"
  66. },
  67. {
  68. "id": "6",
  69. "leave_type": "3",
  70. "leave_amount": "5",
  71. "add_public_holidays": "0",
  72. "jobcontract_revision_id": "8"
  73. }
  74. ]
  75. },
  76. "api.HRJobDetails.get": {
  77. "is_error": 0,
  78. "version": 3,
  79. "count": 1,
  80. "id": 2,
  81. "values": [
  82. {
  83. "id": "2",
  84. "position": "developer",
  85. "title": "developer",
  86. "contract_type": "Contractor",
  87. "period_start_date": "2017-03-28",
  88. "location": "Home",
  89. "jobcontract_revision_id": "8"
  90. }
  91. ]
  92. }
  93. }
  94. ]
  95. }
  96. }
  97. ]
  98. }
  99. */
  100. getAllContractEntitlements: funciton (contactId,params) {
  101. params = params || {};
  102. params.contact_id = contactId
  103.  
  104. return this.sendGET('HRJobContract', 'get', params, false)
  105. .then(function (data) {
  106. var contractEntitlements = [];
  107.  
  108. _.each(data.values, function (contract) {
  109. var contractEntitlement = {};
  110. _.each(contract['api.HRJobContractRevision.get'].values, function (jobContractRevision) {
  111. _.each(jobContractRevision['api.HRJobLeave.get'].values, function (jobLeaves) {
  112. _.each(jobLeaves.values, function (jobLeave) {
  113. contractEntitlement.leaveType = jobLeave.leave_type;
  114. contractEntitlement.leaveAmount = jobLeave.leave_amount;
  115. });
  116. });
  117. _.each(jobContractRevision['api.HRJobDetails.get'].values, function (jobDetails) {
  118. _.each(jobDetails.values, function (jobDetail) {
  119. contractEntitlement.position = jobDetail.position;
  120. contractEntitlement.periodStartDate = jobDetail.period_start_date;
  121. contractEntitlement.periodEndDate = jobDetail.period_end_date;
  122. });
  123. });
  124. contractEntitlements.push(contractEntitlement);
  125. });
  126. });
  127. };
  128. });
  129. return contractEntitlements;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement