zudello-integration-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/README.md +1 -0
  2. package/package.json +23 -0
  3. package/src/index.js +62 -0
  4. package/src/integrations/samples/bc-zudello/account.js +40 -0
  5. package/src/integrations/samples/bc-zudello/accountingPeriod.js +52 -0
  6. package/src/integrations/samples/bc-zudello/currency.js +42 -0
  7. package/src/integrations/samples/bc-zudello/customer.js +45 -0
  8. package/src/integrations/samples/bc-zudello/dimension.js +85 -0
  9. package/src/integrations/samples/bc-zudello/employee.js +38 -0
  10. package/src/integrations/samples/bc-zudello/fixedAsset.js +48 -0
  11. package/src/integrations/samples/bc-zudello/item.js +45 -0
  12. package/src/integrations/samples/bc-zudello/itemCategory.js +37 -0
  13. package/src/integrations/samples/bc-zudello/location.js +37 -0
  14. package/src/integrations/samples/bc-zudello/paymentMethod.js +38 -0
  15. package/src/integrations/samples/bc-zudello/paymentTerm.js +41 -0
  16. package/src/integrations/samples/bc-zudello/project.js +38 -0
  17. package/src/integrations/samples/bc-zudello/purchaseCredit.js +109 -0
  18. package/src/integrations/samples/bc-zudello/purchaseInvoice.js +138 -0
  19. package/src/integrations/samples/bc-zudello/purchaseOrder.js +150 -0
  20. package/src/integrations/samples/bc-zudello/purchaseOrderFetch.js +100 -0
  21. package/src/integrations/samples/bc-zudello/supplier.js +40 -0
  22. package/src/integrations/samples/bc-zudello/taxRate.js +39 -0
  23. package/src/integrations/samples/bc-zudello/uom.js +42 -0
  24. package/src/integrations/samples/dear-zudello/account.js +20 -0
  25. package/src/integrations/samples/dear-zudello/customer.js +23 -0
  26. package/src/integrations/samples/dear-zudello/item.js +30 -0
  27. package/src/integrations/samples/dear-zudello/location.js +19 -0
  28. package/src/integrations/samples/dear-zudello/salesOrder.js +126 -0
  29. package/src/integrations/samples/dear-zudello/supplier.js +23 -0
  30. package/src/integrations/samples/dear-zudello/taxRate.js +19 -0
  31. package/src/integrations/samples/fo-zudello/account.js +20 -0
  32. package/src/integrations/samples/fo-zudello/costCentre.js +20 -0
  33. package/src/integrations/samples/fo-zudello/department.js +20 -0
  34. package/src/integrations/samples/fo-zudello/item.js +21 -0
  35. package/src/integrations/samples/fo-zudello/location.js +20 -0
  36. package/src/integrations/samples/fo-zudello/project.js +18 -0
  37. package/src/integrations/samples/fo-zudello/subsidiary.js +20 -0
  38. package/src/integrations/samples/fo-zudello/supplier.js +23 -0
  39. package/src/integrations/samples/fo-zudello/taxRate.js +20 -0
  40. package/src/integrations/samples/intacct-zudello/account.js +56 -0
  41. package/src/integrations/samples/intacct-zudello/accountGroup.js +54 -0
  42. package/src/integrations/samples/intacct-zudello/accountingPeriod.js +67 -0
  43. package/src/integrations/samples/intacct-zudello/apBill.js +146 -0
  44. package/src/integrations/samples/intacct-zudello/apBillFetch.js +195 -0
  45. package/src/integrations/samples/intacct-zudello/costCentre.js +54 -0
  46. package/src/integrations/samples/intacct-zudello/costType.js +54 -0
  47. package/src/integrations/samples/intacct-zudello/customerCategory.js +54 -0
  48. package/src/integrations/samples/intacct-zudello/customerGroup.js +54 -0
  49. package/src/integrations/samples/intacct-zudello/department.js +54 -0
  50. package/src/integrations/samples/intacct-zudello/employee.js +51 -0
  51. package/src/integrations/samples/intacct-zudello/expense-create.js +156 -0
  52. package/src/integrations/samples/intacct-zudello/item.js +64 -0
  53. package/src/integrations/samples/intacct-zudello/itemCategory.js +54 -0
  54. package/src/integrations/samples/intacct-zudello/itemGroup.js +54 -0
  55. package/src/integrations/samples/intacct-zudello/location.js +54 -0
  56. package/src/integrations/samples/intacct-zudello/paymentTerm.js +56 -0
  57. package/src/integrations/samples/intacct-zudello/project.js +54 -0
  58. package/src/integrations/samples/intacct-zudello/projectGroup.js +54 -0
  59. package/src/integrations/samples/intacct-zudello/projectTask.js +40 -0
  60. package/src/integrations/samples/intacct-zudello/subsidiary.js +54 -0
  61. package/src/integrations/samples/intacct-zudello/supplier.js +168 -0
  62. package/src/integrations/samples/intacct-zudello/supplierCategory.js +54 -0
  63. package/src/integrations/samples/intacct-zudello/supplierGroup.js +54 -0
  64. package/src/integrations/samples/intacct-zudello/supplierV2.js +64 -0
  65. package/src/integrations/samples/intacct-zudello/taxRate.js +34 -0
  66. package/src/integrations/samples/intacct-zudello/taxSolution.js +35 -0
  67. package/src/integrations/samples/intacct-zudello/uom.js +37 -0
  68. package/src/integrations/samples/intacct-zudello/warehouse.js +54 -0
  69. package/src/integrations/samples/intacct-zudello/zone.js +54 -0
  70. package/src/integrations/samples/nexvia-zudello/account.js +20 -0
  71. package/src/integrations/samples/nexvia-zudello/costCentre.js +19 -0
  72. package/src/integrations/samples/nexvia-zudello/costType.js +19 -0
  73. package/src/integrations/samples/nexvia-zudello/currency.js +20 -0
  74. package/src/integrations/samples/nexvia-zudello/department.js +20 -0
  75. package/src/integrations/samples/nexvia-zudello/itemCategory.js +19 -0
  76. package/src/integrations/samples/nexvia-zudello/location.js +20 -0
  77. package/src/integrations/samples/nexvia-zudello/project.js +20 -0
  78. package/src/integrations/samples/nexvia-zudello/supplier.js +21 -0
  79. package/src/integrations/samples/nexvia-zudello/taxRate.js +21 -0
  80. package/src/integrations/samples/nexvia-zudello/uom.js +19 -0
  81. package/src/integrations/samples/nexvia-zudello/zone.js +20 -0
  82. package/src/integrations/samples/zenoti-zudello/location.js +20 -0
  83. package/src/integrations/samples/zenoti-zudello/product.js +32 -0
  84. package/src/integrations/samples/zenoti-zudello/purchaseOrder.js +193 -0
  85. package/src/sdk/Auth.js +42 -0
  86. package/src/sdk/Base.js +118 -0
  87. package/src/sdk/BusinessCentral.js +31 -0
  88. package/src/sdk/Dear.js +31 -0
  89. package/src/sdk/Fo.js +31 -0
  90. package/src/sdk/Intacct.js +103 -0
  91. package/src/sdk/JobReady.js +31 -0
  92. package/src/sdk/MYOBAcumatica.js +33 -0
  93. package/src/sdk/Netsuite.js +31 -0
  94. package/src/sdk/NetsuiteSOAP.js +92 -0
  95. package/src/sdk/Nexvia.js +31 -0
  96. package/src/sdk/RetailExpress.js +31 -0
  97. package/src/sdk/Sybiz.js +31 -0
  98. package/src/sdk/Zenoti.js +31 -0
  99. package/src/sdk/Zudello.js +206 -0
  100. package/src/sdk/submodules/bc/Universal.js +109 -0
  101. package/src/sdk/submodules/dear/Universal.js +110 -0
  102. package/src/sdk/submodules/fo/Universal.js +111 -0
  103. package/src/sdk/submodules/intacct/Account.js +31 -0
  104. package/src/sdk/submodules/intacct/AccountGroup.js +31 -0
  105. package/src/sdk/submodules/intacct/AccountingPeriod.js +31 -0
  106. package/src/sdk/submodules/intacct/ApAdjustment.js +35 -0
  107. package/src/sdk/submodules/intacct/ApBill.js +52 -0
  108. package/src/sdk/submodules/intacct/ApTerm.js +31 -0
  109. package/src/sdk/submodules/intacct/ArAdjustment.js +35 -0
  110. package/src/sdk/submodules/intacct/ArInvoice.js +35 -0
  111. package/src/sdk/submodules/intacct/ArTerm.js +31 -0
  112. package/src/sdk/submodules/intacct/Budget.js +31 -0
  113. package/src/sdk/submodules/intacct/Class.js +31 -0
  114. package/src/sdk/submodules/intacct/CostType.js +31 -0
  115. package/src/sdk/submodules/intacct/Customer.js +31 -0
  116. package/src/sdk/submodules/intacct/CustomerGroup.js +31 -0
  117. package/src/sdk/submodules/intacct/CustomerType.js +31 -0
  118. package/src/sdk/submodules/intacct/Department.js +31 -0
  119. package/src/sdk/submodules/intacct/Employee.js +31 -0
  120. package/src/sdk/submodules/intacct/Entity.js +31 -0
  121. package/src/sdk/submodules/intacct/File.js +26 -0
  122. package/src/sdk/submodules/intacct/Item.js +31 -0
  123. package/src/sdk/submodules/intacct/ItemGroup.js +31 -0
  124. package/src/sdk/submodules/intacct/Location.js +31 -0
  125. package/src/sdk/submodules/intacct/PoDocument.js +52 -0
  126. package/src/sdk/submodules/intacct/ProductLine.js +31 -0
  127. package/src/sdk/submodules/intacct/Project.js +31 -0
  128. package/src/sdk/submodules/intacct/ProjectGroup.js +31 -0
  129. package/src/sdk/submodules/intacct/Task.js +31 -0
  130. package/src/sdk/submodules/intacct/TaxDetail.js +31 -0
  131. package/src/sdk/submodules/intacct/TaxGroups.js +31 -0
  132. package/src/sdk/submodules/intacct/TaxSolution.js +31 -0
  133. package/src/sdk/submodules/intacct/Universal.js +139 -0
  134. package/src/sdk/submodules/intacct/Uom.js +31 -0
  135. package/src/sdk/submodules/intacct/Vendor.js +31 -0
  136. package/src/sdk/submodules/intacct/VendorGroup.js +31 -0
  137. package/src/sdk/submodules/intacct/VendorTypes.js +31 -0
  138. package/src/sdk/submodules/intacct/Warehouse.js +31 -0
  139. package/src/sdk/submodules/intacct/Zone.js +31 -0
  140. package/src/sdk/submodules/intacct/apAdjustment/Item.js +31 -0
  141. package/src/sdk/submodules/intacct/apBill/Item.js +31 -0
  142. package/src/sdk/submodules/intacct/arAdjustment/Item.js +31 -0
  143. package/src/sdk/submodules/intacct/arInvoice/Item.js +31 -0
  144. package/src/sdk/submodules/intacct/poDocument/Item.js +31 -0
  145. package/src/sdk/submodules/jobready/Universal.js +107 -0
  146. package/src/sdk/submodules/myobAcumatica/OData.js +109 -0
  147. package/src/sdk/submodules/myobAcumatica/Universal.js +109 -0
  148. package/src/sdk/submodules/netsuite/Universal.js +97 -0
  149. package/src/sdk/submodules/netsuite-soap/PurchaseOrder.js +39 -0
  150. package/src/sdk/submodules/netsuite-soap/Receipt.js +39 -0
  151. package/src/sdk/submodules/netsuite-soap/Universal.js +124 -0
  152. package/src/sdk/submodules/netsuite-soap/UniversalTransaction.js +138 -0
  153. package/src/sdk/submodules/netsuite-soap/VendorBill.js +41 -0
  154. package/src/sdk/submodules/netsuite-soap/VendorCredit.js +39 -0
  155. package/src/sdk/submodules/nexvia/Universal.js +108 -0
  156. package/src/sdk/submodules/retailExpress/Universal.js +107 -0
  157. package/src/sdk/submodules/sybiz/Universal.js +108 -0
  158. package/src/sdk/submodules/zenoti/Universal.js +110 -0
  159. package/src/sdk/submodules/zudello/Account.js +63 -0
  160. package/src/sdk/submodules/zudello/AccountGroup.js +63 -0
  161. package/src/sdk/submodules/zudello/AccountingPeriod.js +63 -0
  162. package/src/sdk/submodules/zudello/CostCentre.js +63 -0
  163. package/src/sdk/submodules/zudello/CostType.js +63 -0
  164. package/src/sdk/submodules/zudello/Currency.js +63 -0
  165. package/src/sdk/submodules/zudello/Customer.js +63 -0
  166. package/src/sdk/submodules/zudello/CustomerCategory.js +63 -0
  167. package/src/sdk/submodules/zudello/CustomerGroup.js +63 -0
  168. package/src/sdk/submodules/zudello/Department.js +63 -0
  169. package/src/sdk/submodules/zudello/Employee.js +63 -0
  170. package/src/sdk/submodules/zudello/FixedAsset.js +63 -0
  171. package/src/sdk/submodules/zudello/Item.js +63 -0
  172. package/src/sdk/submodules/zudello/ItemCategory.js +63 -0
  173. package/src/sdk/submodules/zudello/ItemGroup.js +63 -0
  174. package/src/sdk/submodules/zudello/Location.js +63 -0
  175. package/src/sdk/submodules/zudello/PaymentMethod.js +63 -0
  176. package/src/sdk/submodules/zudello/PaymentTerm.js +63 -0
  177. package/src/sdk/submodules/zudello/Project.js +63 -0
  178. package/src/sdk/submodules/zudello/ProjectGroup.js +63 -0
  179. package/src/sdk/submodules/zudello/ProjectTask.js +63 -0
  180. package/src/sdk/submodules/zudello/PurchaseOrder.js +63 -0
  181. package/src/sdk/submodules/zudello/Subsidiary.js +63 -0
  182. package/src/sdk/submodules/zudello/Supplier.js +63 -0
  183. package/src/sdk/submodules/zudello/SupplierCategory.js +63 -0
  184. package/src/sdk/submodules/zudello/SupplierGroup.js +63 -0
  185. package/src/sdk/submodules/zudello/Universal.js +31 -0
  186. package/src/sdk/submodules/zudello/Uom.js +63 -0
  187. package/src/sdk/submodules/zudello/Warehouse.js +63 -0
  188. package/src/sdk/submodules/zudello/Zone.js +63 -0
  189. package/src/sdk/submodules/zudello/tax/Rate.js +63 -0
  190. package/src/sdk/submodules/zudello/tax/Solution.js +63 -0
  191. package/src/utils/apiInstance.js +198 -0
  192. package/src/utils/config.js +18 -0
  193. package/src/utils/logger.js +122 -0
  194. package/src/utils/metadata.js +102 -0
  195. package/src/utils/miscHelper.js +24 -0
  196. package/src/utils/modelHelper.js +140 -0
  197. package/src/utils/properties.js +32 -0
  198. package/src/utils/responseHandler.js +28 -0
  199. package/src/utils/s3Client.js +128 -0
  200. package/src/utils/tags.js +32 -0
  201. package/src/utils/validator.js +73 -0
@@ -0,0 +1,146 @@
1
+ const handler = async (providedData) => {
2
+ const { payload } = providedData
3
+
4
+ const model = payload?.resource?.model || null
5
+ const uuid = payload?.resource?.uuid || null
6
+
7
+ logger.log(payload)
8
+ logger.log(model)
9
+ logger.log(uuid)
10
+
11
+ if (!model || !uuid) return
12
+
13
+ const fetchedItem = await Zudello.fetch({ model, uuid })
14
+
15
+ logger.log(fetchedItem)
16
+
17
+ if (!fetchedItem?.data?.data) return
18
+
19
+ const data = fetchedItem.data.data
20
+
21
+ logger.log(data)
22
+
23
+ const mapLine = line => ({
24
+ TAXTYPE: line.tax_rate?.external_id,
25
+ ACCOUNTNO: line.account?.external_id,
26
+ LOCATIONID: line.location?.external_id,
27
+ DEPARTMENTID: line.department?.external_id,
28
+ CLASSID: line.cost_centre?.external_id,
29
+ ITEMID: line.item?.external_id,
30
+ SUBSIDIARYID: line.subsidiary?.external_id,
31
+ TRXAMOUNT: line.total_exclusive,
32
+ TAXAMOUNT: line.tax_amount,
33
+ ENTRYDESCRIPTION: line.description,
34
+ customFields: [{ field_name: "QTY", field_value: line.quantity }]
35
+ })
36
+
37
+ const lines = data.lines?.map(mapLine) || []
38
+
39
+ const getFormattedDate = (date) => date ? moment(date).format('MM/DD/YYYY') : null
40
+
41
+ const getFileNameFromUrl = (url) => {
42
+ const regex = /[^/?#]+(?=\?|$)/
43
+ const matches = url.match(regex)
44
+ return matches ? matches[0] : null
45
+ }
46
+
47
+ const datePosted = getFormattedDate(data.date_posted) || getFormattedDate(data.date_issued)
48
+
49
+ const dateDue = getFormattedDate(data.date_due)
50
+
51
+ const fileAttachment = await Zudello.getFileAttachment({ uuid, type: 'EXTRACTED' })
52
+
53
+ if (!fileAttachment.success) {
54
+ logger.log('Failed to fetch attachment file')
55
+ return
56
+ }
57
+
58
+ logger.log('------------------------')
59
+ logger.log(fileAttachment)
60
+ logger.log('------------------------')
61
+
62
+ const metaFolderName = metadata.get('folder_name', 'Zudello Attachments')
63
+ const attachmentId = moment().unix()
64
+
65
+ const createAttachmentPayload = {
66
+ ENTITY_ID: { isMap: false, value: null },
67
+ PARENT_FOLDER_NAME: { isMap: false, value: metaFolderName },
68
+ PARENT_NAME: { isMap: false, value: `${_.get(data, "document_type")} ${_.get(data, "document_number")}` },
69
+ ATTACHMENT_ID: { isMap: false, value: attachmentId },
70
+ ATTACHMENT_URL: { isMap: false, value: fileAttachment.data },
71
+ ATTACHMENT_DESC: { isMap: false, value: `${_.get(data, "document_type")} ${_.get(data, "document_number")}` },
72
+ MIME_TYPE: { isMap: false, value: "application/pdf" },
73
+ FILE_NAME: { isMap: false, value: getFileNameFromUrl(fileAttachment.data) },
74
+ }
75
+
76
+ logger.log('------------------------')
77
+ logger.log(createAttachmentPayload)
78
+ logger.log('------------------------')
79
+
80
+ const intacctAttachment = await Intacct.file.create(createAttachmentPayload)
81
+
82
+ logger.log(JSON.stringify(intacctAttachment.data.response))
83
+
84
+ const createPayload = {
85
+ VENDORID: { isMap: false, value: data.supplier?.external_id },
86
+ WHENCREATED: { isMap: false, value: getFormattedDate(data.date_issued) },
87
+ WHENPOSTED: { isMap: false, value: datePosted },
88
+ WHENDUE: { isMap: false, value: dateDue },
89
+ EXCH_RATE_DATE: { isMap: false, value: datePosted },
90
+ RECORDID: { isMap: false, value: data.document_number },
91
+ DOCNUMBER: { isMap: false, value: data.reference },
92
+ DESCRIPTION: { isMap: false, value: fetchedItem.data.short_url },
93
+ CURRENCY: { isMap: false, value: data.currency?.code },
94
+ BASECURR: { isMap: false, value: data.currency?.code },
95
+ TAXSOLUTIONID: { isMap: false, value: "Australia - GST" },
96
+ APBILLITEMS: { isMap: true, value: `{{${JSON.stringify(lines)}}}` },
97
+ SUPDOCID: { isMap: true, value: attachmentId },
98
+ customFields: [{ field_name: "ARI_HEADER_LOCATION", field_value: lines[0]?.LOCATIONID }]
99
+ }
100
+
101
+ logger.log(createPayload)
102
+
103
+ const apBillResponse = await Intacct.apBill.create(createPayload)
104
+
105
+ logger.log(JSON.stringify(apBillResponse))
106
+
107
+ if (!apBillResponse?.data) return
108
+
109
+ const apBillResponseData = apBillResponse.data
110
+ const operationResult = apBillResponseData[0]?.operation[0]?.result[0]
111
+
112
+ let status = "COMPLETE"
113
+
114
+ if (operationResult?.status[0] === "failure") {
115
+ logger.log(operationResult?.errormessage[0]?.error[0]?.description2[0])
116
+ status = "UNABLE"
117
+ }
118
+
119
+ const resultPayload = {
120
+ model,
121
+ module: data.module,
122
+ submodule: data.submodule,
123
+ data: {
124
+ uuid,
125
+ status,
126
+ external_id: operationResult?.data?.[0]?.apbill?.[0]?.RECORDNO?.[0] || data.external_id,
127
+ log_messages: status === "UNABLE" ? {
128
+ replace: true,
129
+ items: [{
130
+ create: true,
131
+ data: {
132
+ status_code: 404,
133
+ body: JSON.stringify({ message: _.unescape(operationResult?.errormessage?.[0]?.error?.[0]?.description2?.[0]) }),
134
+ parse_as: "SENTENCE_ERROR"
135
+ }
136
+ }]
137
+ } : null
138
+ }
139
+ }
140
+
141
+ logger.log(JSON.stringify(resultPayload))
142
+
143
+ const zudelloUpdateResponse = await Zudello.update(resultPayload)
144
+
145
+ logger.log(JSON.stringify(zudelloUpdateResponse))
146
+ }
@@ -0,0 +1,195 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 50, offset: 0, include: ['WHENMODIFIED'], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters = [{
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ }]
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const itemPaginated of Intacct.apBill.autoPaginationList(fetchData)) {
16
+ logger.log(itemPaginated)
17
+
18
+ if (!Array.isArray(itemPaginated?.data)) {
19
+ continue
20
+ }
21
+
22
+ const itemIds = itemPaginated?.data?.map(pageItem => pageItem["RECORDNO"])
23
+ const items = await Intacct.universal.read({ type: "APBILL", keys: itemIds.join(', ') })
24
+
25
+ logger.log(items?.data?.response[0]?.operation[0]?.result[0]?.data[0]?.APBILL)
26
+
27
+ const data = _.map(items?.data?.response[0]?.operation[0]?.result[0]?.data[0]?.APBILL, (result) => {
28
+ return {
29
+ model: "Transaction",
30
+ data: {
31
+ module: "PURCHASING",
32
+ submodule: "INVOICE",
33
+ document_type: "EXPENSE",
34
+ "external_id": _.get(result, 'RECORDNO.0'),
35
+ "supplier": {
36
+ "fetch": true,
37
+ "create": true,
38
+ "update": false,
39
+ "data": {
40
+ "external_id": _.get(result, 'VENDORID.0')
41
+ }
42
+ },
43
+ "company_name": _.get(result, 'VENDORNAME.0'),
44
+ "company_tax": _.get(result, 'TAXID.0'),
45
+ "currency": {
46
+ "fetch": true,
47
+ "create": true,
48
+ "update": false,
49
+ "data": {
50
+ "external_id": _.get(result, 'CURRENCY.0')
51
+ }
52
+ },
53
+ "document_number": _.get(result, 'RECORDID.0'),
54
+ "reference": _.get(result, 'DOCNUMBER.0'),
55
+ "date_issued": _.get(result, 'WHENCREATED.0'),
56
+ "date_due": _.get(result, 'WHENDUE.0'),
57
+ "total": _.get(result, 'TOTALENTERED.0'),
58
+ "status": "COMPLETE",
59
+ "lines": {
60
+ "replace": false,
61
+ "items": _.flatten(_.map(_.get(result, 'APBILLITEMS.0.apbillitem'), (x) => {
62
+ const taxRate = _.get(x, "DETAILID.0")
63
+ const item = _.get(x, 'ITEMID.0')
64
+ const account = _.get(x,'ACCOUNTNO.0')
65
+ const department = _.get(x, 'DEPARTMENTID.0')
66
+ const location = _.get(x, 'LOCATIONID.0')
67
+ const costCentre = _.get(x, 'CLASSID.0')
68
+ const costType = _.get(x, "TASKID.0")
69
+ const project = _.get(x, "PROJECTID.0")
70
+
71
+ const itemData = {
72
+ "create": true,
73
+ "update": true,
74
+ "data": {
75
+ "external_id": _.get(x, 'RECORDNO.0'),
76
+ "description": _.get(x, 'ENTRYDESCRIPTION.0'),
77
+ "line_number": _.get(x, 'LINE_NO.0'),
78
+ "quantity": _.isNumber(_.get(x,'QTY.0',''))? _.get(x,'QTY.0') : 1,
79
+ "unit_price": _.isNumber(_.get(x,'QTY.0',''))? _.get(x, 'TRX_AMOUNT.0')/_.get(x,'QTY.0') : _.get(x, 'TRX_AMOUNT.0'),
80
+ "total": _.get(x, 'TRX_AMOUNT.0')
81
+ }
82
+ }
83
+
84
+ if (taxRate) {
85
+ itemData.data.tax_rate = {
86
+ "fetch": true,
87
+ "create": true,
88
+ "update": false,
89
+ "data": {
90
+ "external_id": _.get(x, "DETAILID.0")
91
+ }
92
+ }
93
+ }
94
+
95
+ if (item) {
96
+ itemData.data.item = {
97
+ "fetch": true,
98
+ "create": true,
99
+ "update": false,
100
+ "data": {
101
+ "external_id": _.get(x, 'ITEMID.0')
102
+ }
103
+ }
104
+ }
105
+ if (account) {
106
+ itemData.data.account = {
107
+ "fetch": true,
108
+ "create": true,
109
+ "update": false,
110
+ "data": {
111
+ "external_id": _.get(x, 'ACCOUNTNO.0')
112
+ }
113
+ }
114
+ }
115
+ if (department) {
116
+ itemData.data.department = {
117
+ "fetch": true,
118
+ "create": true,
119
+ "update": false,
120
+ "data": {
121
+ "external_id": _.get(x, 'DEPARTMENTID.0')
122
+ }
123
+ }
124
+ }
125
+
126
+ if (location) {
127
+ itemData.data.location = {
128
+ "fetch": true,
129
+ "create": true,
130
+ "update": false,
131
+ "data": {
132
+ "external_id": _.get(x, 'LOCATIONID.0')
133
+ }
134
+ }
135
+ }
136
+
137
+ if (costCentre) {
138
+ itemData.data.cost_centre = {
139
+ "fetch": true,
140
+ "create": true,
141
+ "update": false,
142
+ "data": {
143
+ "external_id": _.get(x, 'CLASSID.0')
144
+ }
145
+ }
146
+ }
147
+
148
+ if (costType) {
149
+ itemData.data.cost_type = {
150
+ "fetch": true,
151
+ "create": true,
152
+ "update": false,
153
+ "data": {
154
+ "external_id": _.get(x, "TASKID.0")
155
+ }
156
+ }
157
+ }
158
+
159
+ if (project) {
160
+ itemData.data.project = {
161
+ "fetch": true,
162
+ "create": true,
163
+ "update": false,
164
+ "data": {
165
+ "external_id": _.get(x, "PROJECTID.0")
166
+ }
167
+ }
168
+ }
169
+
170
+ return itemData
171
+ }))
172
+ }
173
+ },
174
+ "enrich": false,
175
+ "submit": false,
176
+ "create": true,
177
+ "update": true,
178
+ "update_status": false
179
+ }
180
+ })
181
+
182
+ logger.log(data)
183
+ const result = await Zudello.updateOrCreate({ data })
184
+ logger.log(result)
185
+
186
+ if (result.success) {
187
+ const lastObject = _.last(itemPaginated.data)
188
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
189
+
190
+ if (updatedLastModified) {
191
+ metadata.set('lastModified', updatedLastModified)
192
+ }
193
+ }
194
+ }
195
+ }
@@ -0,0 +1,54 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 2000, offset: 0, include: ['WHENMODIFIED'], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters = [{
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ }]
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const items of Intacct.class.autoPaginationList(fetchData)) {
16
+ logger.log(items)
17
+
18
+ const data = _.map(items.data, (item) => {
19
+ return {
20
+ "external_id": _.get(item, "CLASSID"),
21
+ "code": _.get(item, "CLASSID"),
22
+ "name": _.get(item, "NAME"),
23
+ "status": _.get(item, "STATUS", "ACTIVE").toUpperCase(),
24
+ }
25
+ })
26
+
27
+ const batchSize = 100
28
+
29
+ for (let i = 0; i < data.length; i += batchSize) {
30
+ const batch = data.slice(i, i + batchSize)
31
+
32
+ logger.log(batch)
33
+
34
+ const result = await Zudello.costCentre.updateOrCreate({ data: batch })
35
+
36
+ logger.log(result)
37
+ logger.log(`Processed batch ${Math.ceil((i + batchSize) / batchSize)} of ${Math.ceil(data.length / batchSize)}`)
38
+
39
+ if (result.success) {
40
+ const lastObject = _.last(items.data)
41
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
42
+
43
+ if (updatedLastModified) {
44
+ metadata.set('lastModified', updatedLastModified)
45
+ }
46
+ }
47
+
48
+ // Introduce a delay of 3 seconds (3000 milliseconds) after each batch
49
+ if (i + batchSize < data.length) {
50
+ await new Promise(resolve => setTimeout(resolve, 3000))
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,54 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 2000, offset: 0, include: ['WHENMODIFIED'], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters = [{
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ }]
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const items of Intacct.costType.autoPaginationList(fetchData)) {
16
+ logger.log(items)
17
+
18
+ const data = _.map(items.data, (item) => {
19
+ return {
20
+ "external_id": _.get(item, "COSTTYPEID"),
21
+ "code": _.get(item, "COSTTYPEID"),
22
+ "name": _.get(item, "NAME"),
23
+ "status": _.get(item, "STATUS", "ACTIVE").toUpperCase(),
24
+ }
25
+ })
26
+
27
+ const batchSize = 100
28
+
29
+ for (let i = 0; i < data.length; i += batchSize) {
30
+ const batch = data.slice(i, i + batchSize)
31
+
32
+ logger.log(batch)
33
+
34
+ const result = await Zudello.costType.updateOrCreate({ data: batch })
35
+
36
+ logger.log(result)
37
+ logger.log(`Processed batch ${Math.ceil((i + batchSize) / batchSize)} of ${Math.ceil(data.length / batchSize)}`)
38
+
39
+ if (result.success) {
40
+ const lastObject = _.last(items.data)
41
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
42
+
43
+ if (updatedLastModified) {
44
+ metadata.set('lastModified', updatedLastModified)
45
+ }
46
+ }
47
+
48
+ // Introduce a delay of 3 seconds (3000 milliseconds) after each batch
49
+ if (i + batchSize < data.length) {
50
+ await new Promise(resolve => setTimeout(resolve, 3000))
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,54 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 2000, offset: 0, include: ['WHENMODIFIED'], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters = [{
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ }]
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const items of Intacct.customerType.autoPaginationList(fetchData)) {
16
+ logger.log(items)
17
+
18
+ const data = _.map(items.data, (item) => {
19
+ return {
20
+ "external_id": _.get(item, "RECORDID"),
21
+ "code": _.get(item, "RECORDID"),
22
+ "name": _.get(item, "NAME"),
23
+ "status": _.get(item, "STATUS", "ACTIVE").toUpperCase(),
24
+ }
25
+ })
26
+
27
+ const batchSize = 100
28
+
29
+ for (let i = 0; i < data.length; i += batchSize) {
30
+ const batch = data.slice(i, i + batchSize)
31
+
32
+ logger.log(batch)
33
+
34
+ const result = await Zudello.customerCategory.updateOrCreate({ data: batch })
35
+
36
+ logger.log(result)
37
+ logger.log(`Processed batch ${Math.ceil((i + batchSize) / batchSize)} of ${Math.ceil(data.length / batchSize)}`)
38
+
39
+ if (result.success) {
40
+ const lastObject = _.last(items.data)
41
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
42
+
43
+ if (updatedLastModified) {
44
+ metadata.set('lastModified', updatedLastModified)
45
+ }
46
+ }
47
+
48
+ // Introduce a delay of 3 seconds (3000 milliseconds) after each batch
49
+ if (i + batchSize < data.length) {
50
+ await new Promise(resolve => setTimeout(resolve, 3000))
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,54 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 2000, offset: 0, include: ['WHENMODIFIED'], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters = [{
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ }]
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const items of Intacct.customerGroup.autoPaginationList(fetchData)) {
16
+ logger.log(items)
17
+
18
+ const data = _.map(items.data, (item) => {
19
+ return {
20
+ "external_id": _.get(item, "ID"),
21
+ "code": _.get(item, "ID"),
22
+ "name": _.get(item, "NAME"),
23
+ "status": "ACTIVE",
24
+ }
25
+ })
26
+
27
+ const batchSize = 100
28
+
29
+ for (let i = 0; i < data.length; i += batchSize) {
30
+ const batch = data.slice(i, i + batchSize)
31
+
32
+ logger.log(batch)
33
+
34
+ const result = await Zudello.customerGroup.updateOrCreate({ data: batch })
35
+
36
+ logger.log(result)
37
+ logger.log(`Processed batch ${Math.ceil((i + batchSize) / batchSize)} of ${Math.ceil(data.length / batchSize)}`)
38
+
39
+ if (result.success) {
40
+ const lastObject = _.last(items.data)
41
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
42
+
43
+ if (updatedLastModified) {
44
+ metadata.set('lastModified', updatedLastModified)
45
+ }
46
+ }
47
+
48
+ // Introduce a delay of 3 seconds (3000 milliseconds) after each batch
49
+ if (i + batchSize < data.length) {
50
+ await new Promise(resolve => setTimeout(resolve, 3000))
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,54 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 2000, offset: 0, include: ['WHENMODIFIED'], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters = [{
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ }]
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const items of Intacct.department.autoPaginationList(fetchData)) {
16
+ logger.log(items)
17
+
18
+ const data = _.map(items.data, (item) => {
19
+ return {
20
+ "external_id": _.get(item, "DEPARTMENTID"),
21
+ "code": _.get(item, "DEPARTMENTID"),
22
+ "name": _.get(item, "TITLE"),
23
+ "status": _.get(item, "STATUS", "ACTIVE").toUpperCase(),
24
+ }
25
+ })
26
+
27
+ const batchSize = 100
28
+
29
+ for (let i = 0; i < data.length; i += batchSize) {
30
+ const batch = data.slice(i, i + batchSize)
31
+
32
+ logger.log(batch)
33
+
34
+ const result = await Zudello.department.updateOrCreate({ data: batch })
35
+
36
+ logger.log(result)
37
+ logger.log(`Processed batch ${Math.ceil((i + batchSize) / batchSize)} of ${Math.ceil(data.length / batchSize)}`)
38
+
39
+ if (result.success) {
40
+ const lastObject = _.last(items.data)
41
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
42
+
43
+ if (updatedLastModified) {
44
+ metadata.set('lastModified', updatedLastModified)
45
+ }
46
+ }
47
+
48
+ // Introduce a delay of 3 seconds (3000 milliseconds) after each batch
49
+ if (i + batchSize < data.length) {
50
+ await new Promise(resolve => setTimeout(resolve, 3000))
51
+ }
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,51 @@
1
+ const handler = async (providedData) => {
2
+ const lastModified = metadata.get('lastModified')
3
+ const fetchData = { pageSize: 100, offset: 0, include: ['WHENMODIFIED'], filters: [{ fName: "VENDTYPE", operator: "equalto", fValue: "Employees" }], orderBy: 'WHENMODIFIED' }
4
+
5
+ if (lastModified) {
6
+ fetchData.filters.push({
7
+ fName: { value: 'WHENMODIFIED' },
8
+ operator: { value: 'greaterthan' },
9
+ fValue: { value: lastModified }
10
+ })
11
+ }
12
+
13
+ logger.log(fetchData)
14
+
15
+ for await (const items of Intacct.vendor.autoPaginationList(fetchData)) {
16
+ logger.log(items)
17
+
18
+ const data = _.map(items.data, (result) => {
19
+ return {
20
+ "external_id": _.get(result, "VENDORID"),
21
+ "first_name": _.get(result, "DISPLAYCONTACT.FIRSTNAME"),
22
+ "last_name": _.get(result, "DISPLAYCONTACT.LASTNAME"),
23
+ "emails": {
24
+ "replace": true,
25
+ "items": (_.get(result, "DISPLAYCONTACT.EMAIL1")) ?[
26
+ {
27
+ "create": true,
28
+ "data": {
29
+ "email": _.get(result, "DISPLAYCONTACT.EMAIL1")
30
+ }
31
+ }
32
+ ] : []
33
+ },
34
+ "status": _.get(result, "STATUS").toUpperCase()
35
+ }
36
+ })
37
+
38
+
39
+ const result = await Zudello.employee.updateOrCreate({ data })
40
+ logger.log(JSON.stringify(result))
41
+ if (result.success) {
42
+ const lastObject = _.last(items.data)
43
+ const updatedLastModified = lastObject ? lastObject.WHENMODIFIED : null
44
+
45
+ if (updatedLastModified) {
46
+ metadata.set('lastModified', updatedLastModified)
47
+ }
48
+ }
49
+
50
+ }
51
+ }