repzo-sap-absjo 1.0.10 → 1.0.12

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 (79) hide show
  1. package/changelog.md +2 -0
  2. package/lib/actions/create_invoice.d.ts +19 -13
  3. package/lib/actions/create_invoice.js +356 -208
  4. package/lib/actions/create_payment.d.ts +4 -1
  5. package/lib/actions/create_payment.js +191 -117
  6. package/lib/actions/create_proforma.d.ts +4 -1
  7. package/lib/actions/create_proforma.js +285 -155
  8. package/lib/actions/create_return_invoice.d.ts +4 -1
  9. package/lib/actions/create_return_invoice.js +312 -169
  10. package/lib/actions/create_transfer.d.ts +4 -1
  11. package/lib/actions/create_transfer.js +223 -136
  12. package/lib/actions/index.js +23 -15
  13. package/lib/commands/adjust_inventory.d.ts +4 -2
  14. package/lib/commands/adjust_inventory.js +290 -160
  15. package/lib/commands/bank.d.ts +4 -2
  16. package/lib/commands/bank.js +279 -157
  17. package/lib/commands/basic.js +66 -47
  18. package/lib/commands/category.d.ts +3 -1
  19. package/lib/commands/category.js +178 -104
  20. package/lib/commands/channel.d.ts +3 -1
  21. package/lib/commands/channel.js +198 -117
  22. package/lib/commands/client.d.ts +34 -32
  23. package/lib/commands/client.js +404 -244
  24. package/lib/commands/client_disabled.d.ts +3 -1
  25. package/lib/commands/client_disabled.js +163 -94
  26. package/lib/commands/index.d.ts +15 -11
  27. package/lib/commands/index.js +60 -60
  28. package/lib/commands/join.js +192 -66
  29. package/lib/commands/measureunit.d.ts +19 -14
  30. package/lib/commands/measureunit.js +289 -191
  31. package/lib/commands/measureunit_family.d.ts +10 -8
  32. package/lib/commands/measureunit_family.js +250 -138
  33. package/lib/commands/payment_term.d.ts +3 -1
  34. package/lib/commands/payment_term.js +202 -123
  35. package/lib/commands/price_list.d.ts +15 -15
  36. package/lib/commands/price_list.js +612 -326
  37. package/lib/commands/product.d.ts +32 -30
  38. package/lib/commands/product.js +426 -243
  39. package/lib/commands/product_disabled.d.ts +3 -1
  40. package/lib/commands/product_disabled.js +164 -94
  41. package/lib/commands/rep.js +221 -141
  42. package/lib/commands/tag.js +174 -109
  43. package/lib/commands/tax.js +177 -112
  44. package/lib/commands/warehouse.d.ts +3 -1
  45. package/lib/commands/warehouse.js +207 -119
  46. package/lib/index.d.ts +21 -12
  47. package/lib/test/actions/create_invoice.js +193 -188
  48. package/lib/test/actions/create_payment.js +112 -107
  49. package/lib/test/actions/create_proforma.js +220 -216
  50. package/lib/test/actions/create_return_invoice.js +205 -200
  51. package/lib/test/actions/create_transfer.js +120 -115
  52. package/lib/test/commands/adjust_inventory.js +90 -90
  53. package/lib/test/commands/bank.js +90 -90
  54. package/lib/test/commands/basic.js +328 -327
  55. package/lib/test/commands/category.js +90 -90
  56. package/lib/test/commands/channel.js +90 -90
  57. package/lib/test/commands/client.js +355 -353
  58. package/lib/test/commands/client_disabled.js +90 -90
  59. package/lib/test/commands/join.js +328 -327
  60. package/lib/test/commands/measureunit.js +90 -90
  61. package/lib/test/commands/measureunit_family.js +90 -90
  62. package/lib/test/commands/payment_term.js +90 -90
  63. package/lib/test/commands/price_list.js +337 -334
  64. package/lib/test/commands/product.js +90 -90
  65. package/lib/test/commands/product_disabled.js +90 -90
  66. package/lib/test/commands/rep.js +346 -344
  67. package/lib/test/commands/tag.js +90 -90
  68. package/lib/test/commands/tax.js +90 -90
  69. package/lib/test/commands/warehouse.js +90 -90
  70. package/lib/types.d.ts +83 -60
  71. package/lib/util.d.ts +70 -19
  72. package/lib/util.js +170 -144
  73. package/package.json +2 -2
  74. package/src/actions/create_invoice.ts +11 -16
  75. package/src/actions/create_payment.ts +11 -16
  76. package/src/actions/create_proforma.ts +19 -24
  77. package/src/actions/create_return_invoice.ts +11 -16
  78. package/src/actions/create_transfer.ts +23 -28
  79. package/src/commands/product.ts +1 -0
@@ -1,259 +1,419 @@
1
1
  import Repzo from "repzo";
2
- import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
2
+ import {
3
+ _create,
4
+ update_bench_time,
5
+ date_formatting,
6
+ set_error,
7
+ } from "../util.js";
3
8
  export const sync_client = async (commandEvent) => {
4
- var _a, _b, _c, _d, _e, _f, _g, _h;
5
- const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
6
- env: commandEvent.env,
9
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10
+ const repzo = new Repzo(
11
+ (_a = commandEvent.app.formData) === null || _a === void 0
12
+ ? void 0
13
+ : _a.repzoApiKey,
14
+ {
15
+ env: commandEvent.env,
16
+ }
17
+ );
18
+ const commandLog = new Repzo.CommandLog(
19
+ repzo,
20
+ commandEvent.app,
21
+ commandEvent.command
22
+ );
23
+ try {
24
+ // console.log("sync_client");
25
+ const new_bench_time = new Date().toISOString();
26
+ const bench_time_key = "bench_time_client";
27
+ await commandLog.load(commandEvent.sync_id);
28
+ await commandLog.addDetail("Repzo SAP: Started Syncing Clients").commit();
29
+ const nameSpace = commandEvent.nameSpace.join("_");
30
+ const result = {
31
+ sap_total: 0,
32
+ repzo_total: 0,
33
+ created: 0,
34
+ updated: 0,
35
+ failed: 0,
36
+ };
37
+ const failed_docs_report = [];
38
+ // Get SAP CLients to be created/updated
39
+ const sap_clients = await get_sap_clients(
40
+ commandEvent.app.formData.sapHostUrl,
41
+ {
42
+ updateAt: commandEvent.app.options_formData[bench_time_key],
43
+ GroupCode: commandEvent.app.formData.GroupCode,
44
+ }
45
+ );
46
+ result.sap_total =
47
+ sap_clients === null || sap_clients === void 0
48
+ ? void 0
49
+ : sap_clients.length;
50
+ await commandLog
51
+ .addDetail(
52
+ `${result.sap_total} Customers in SAP changed since ${
53
+ commandEvent.app.options_formData[bench_time_key] || "ever"
54
+ }`
55
+ )
56
+ .commit();
57
+ // Get SAP CLients to be created/updated
58
+ const sap_all_clients = await get_sap_clients(
59
+ commandEvent.app.formData.sapHostUrl,
60
+ {}
61
+ );
62
+ result.sap_total =
63
+ sap_clients === null || sap_clients === void 0
64
+ ? void 0
65
+ : sap_clients.length;
66
+ // Get Repzo Tags
67
+ const repzo_tags = await repzo.tag.find({
68
+ disabled: false,
69
+ per_page: 50000,
70
+ });
71
+ // Get Repzo Channels
72
+ const repzo_channels = await repzo.channel.find({
73
+ disabled: false,
74
+ per_page: 50000,
75
+ });
76
+ // Get Repzo PaymentTerms
77
+ const repzo_payment_terms = await repzo.paymentTerm.find({
78
+ disabled: false,
79
+ per_page: 50000,
80
+ });
81
+ // Get Repzo PriceLists
82
+ const repzo_price_lists = await repzo.priceList.find({
83
+ disabled: false,
84
+ per_page: 50000,
7
85
  });
8
- const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
9
- try {
10
- // console.log("sync_client");
11
- const new_bench_time = new Date().toISOString();
12
- const bench_time_key = "bench_time_client";
13
- await commandLog.load(commandEvent.sync_id);
14
- await commandLog.addDetail("Repzo SAP: Started Syncing Clients").commit();
15
- const nameSpace = commandEvent.nameSpace.join("_");
16
- const result = {
17
- sap_total: 0,
18
- repzo_total: 0,
19
- created: 0,
20
- updated: 0,
21
- failed: 0,
22
- };
23
- const failed_docs_report = [];
24
- // Get SAP CLients to be created/updated
25
- const sap_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {
26
- updateAt: commandEvent.app.options_formData[bench_time_key],
27
- GroupCode: commandEvent.app.formData.GroupCode,
28
- });
29
- result.sap_total = sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.length;
30
- await commandLog
31
- .addDetail(`${result.sap_total} Customers in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
32
- .commit();
33
- // Get SAP CLients to be created/updated
34
- const sap_all_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {});
35
- result.sap_total = sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.length;
36
- // Get Repzo Tags
37
- const repzo_tags = await repzo.tag.find({
38
- disabled: false,
39
- per_page: 50000,
40
- });
41
- // Get Repzo Channels
42
- const repzo_channels = await repzo.channel.find({
43
- disabled: false,
44
- per_page: 50000,
45
- });
46
- // Get Repzo PaymentTerms
47
- const repzo_payment_terms = await repzo.paymentTerm.find({
48
- disabled: false,
49
- per_page: 50000,
50
- });
51
- // Get Repzo PriceLists
52
- const repzo_price_lists = await repzo.priceList.find({
53
- disabled: false,
54
- per_page: 50000,
55
- });
56
- // Get Repzo Clients
57
- const repzo_clients = await repzo.client.find({
58
- per_page: 50000,
59
- project: ["_id", "integration_meta"],
60
- });
61
- result.repzo_total = (_b = repzo_clients === null || repzo_clients === void 0 ? void 0 : repzo_clients.data) === null || _b === void 0 ? void 0 : _b.length;
62
- await commandLog
63
- .addDetail(`${(_c = repzo_clients === null || repzo_clients === void 0 ? void 0 : repzo_clients.data) === null || _c === void 0 ? void 0 : _c.length} Clients in Repzo`)
64
- .commit();
65
- for (let i = 0; i < (sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.length); i++) {
66
- const sap_client = sap_clients[i];
67
- const repzo_client = repzo_clients.data.find((r_client) => { var _a; return ((_a = r_client.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_client.CLIENTID}`; });
68
- const tag = (_d = repzo_tags === null || repzo_tags === void 0 ? void 0 : repzo_tags.data) === null || _d === void 0 ? void 0 : _d.find((tag) => { var _a; return ((_a = tag.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_client.TERRITORYID}`; });
69
- const channel = (_e = repzo_channels === null || repzo_channels === void 0 ? void 0 : repzo_channels.data) === null || _e === void 0 ? void 0 : _e.find((channel) => {
70
- var _a;
71
- return ((_a = channel.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
72
- `${nameSpace}_${sap_client.CLIENTGROUP}`;
86
+ // Get Repzo Clients
87
+ const repzo_clients = await repzo.client.find({
88
+ per_page: 50000,
89
+ project: ["_id", "integration_meta"],
90
+ });
91
+ result.repzo_total =
92
+ (_b =
93
+ repzo_clients === null || repzo_clients === void 0
94
+ ? void 0
95
+ : repzo_clients.data) === null || _b === void 0
96
+ ? void 0
97
+ : _b.length;
98
+ await commandLog
99
+ .addDetail(
100
+ `${
101
+ (_c =
102
+ repzo_clients === null || repzo_clients === void 0
103
+ ? void 0
104
+ : repzo_clients.data) === null || _c === void 0
105
+ ? void 0
106
+ : _c.length
107
+ } Clients in Repzo`
108
+ )
109
+ .commit();
110
+ for (
111
+ let i = 0;
112
+ i <
113
+ (sap_clients === null || sap_clients === void 0
114
+ ? void 0
115
+ : sap_clients.length);
116
+ i++
117
+ ) {
118
+ const sap_client = sap_clients[i];
119
+ const repzo_client = repzo_clients.data.find((r_client) => {
120
+ var _a;
121
+ return (
122
+ ((_a = r_client.integration_meta) === null || _a === void 0
123
+ ? void 0
124
+ : _a.id) == `${nameSpace}_${sap_client.CLIENTID}`
125
+ );
126
+ });
127
+ const tag =
128
+ (_d =
129
+ repzo_tags === null || repzo_tags === void 0
130
+ ? void 0
131
+ : repzo_tags.data) === null || _d === void 0
132
+ ? void 0
133
+ : _d.find((tag) => {
134
+ var _a;
135
+ return (
136
+ ((_a = tag.integration_meta) === null || _a === void 0
137
+ ? void 0
138
+ : _a.id) == `${nameSpace}_${sap_client.TERRITORYID}`
139
+ );
140
+ });
141
+ const channel =
142
+ (_e =
143
+ repzo_channels === null || repzo_channels === void 0
144
+ ? void 0
145
+ : repzo_channels.data) === null || _e === void 0
146
+ ? void 0
147
+ : _e.find((channel) => {
148
+ var _a;
149
+ return (
150
+ ((_a = channel.integration_meta) === null || _a === void 0
151
+ ? void 0
152
+ : _a.id) == `${nameSpace}_${sap_client.CLIENTGROUP}`
153
+ );
73
154
  });
74
- const paymentTerm = (_f = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _f === void 0 ? void 0 : _f.find((paymentTerm) => {
75
- var _a;
76
- return ((_a = paymentTerm.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
77
- `${nameSpace}_${sap_client.PAYMENTTERM}`;
155
+ const paymentTerm =
156
+ (_f =
157
+ repzo_payment_terms === null || repzo_payment_terms === void 0
158
+ ? void 0
159
+ : repzo_payment_terms.data) === null || _f === void 0
160
+ ? void 0
161
+ : _f.find((paymentTerm) => {
162
+ var _a;
163
+ return (
164
+ ((_a = paymentTerm.integration_meta) === null || _a === void 0
165
+ ? void 0
166
+ : _a.id) == `${nameSpace}_${sap_client.PAYMENTTERM}`
167
+ );
78
168
  });
79
- const priceList = (_g = repzo_price_lists === null || repzo_price_lists === void 0 ? void 0 : repzo_price_lists.data) === null || _g === void 0 ? void 0 : _g.find((pricelist) => {
80
- var _a;
81
- return ((_a = pricelist.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
82
- `${nameSpace}_${sap_client.CLIENTPRICELISTID}`;
169
+ const priceList =
170
+ (_g =
171
+ repzo_price_lists === null || repzo_price_lists === void 0
172
+ ? void 0
173
+ : repzo_price_lists.data) === null || _g === void 0
174
+ ? void 0
175
+ : _g.find((pricelist) => {
176
+ var _a;
177
+ return (
178
+ ((_a = pricelist.integration_meta) === null || _a === void 0
179
+ ? void 0
180
+ : _a.id) == `${nameSpace}_${sap_client.CLIENTPRICELISTID}`
181
+ );
83
182
  });
84
- let parent;
85
- if (sap_client.PARENTCODE) {
86
- parent = sap_all_clients.find((c) => c.CLIENTID == sap_client.PARENTCODE);
87
- }
88
- const credit_limit = parent
89
- ? parent.CLIENTCREDITLIMIT
90
- : sap_client.CLIENTCREDITLIMIT;
91
- const client_credit_consumed = parent
92
- ? parent.CLIENTCREDITCONSUMED
93
- : sap_client.CLIENTCREDITCONSUMED;
94
- const body = {
95
- integration_meta: {
96
- id: `${nameSpace}_${sap_client.CLIENTID}`,
97
- PAYMENTTERM: sap_client.PAYMENTTERM,
98
- CLIENTCREDITCONSUMED: parent
99
- ? parent.CLIENTCREDITCONSUMED
100
- : sap_client.CLIENTCREDITCONSUMED,
101
- CLIENTMAXCHEQUEVALUE: parent
102
- ? parent.CLIENTMAXCHEQUEVALUE
103
- : sap_client.CLIENTMAXCHEQUEVALUE,
104
- CLIENTCREDITLIMIT: parent
105
- ? parent.CLIENTCREDITLIMIT
106
- : sap_client.CLIENTCREDITLIMIT,
107
- CLIENTPRICELISTID: sap_client.CLIENTPRICELISTID,
108
- },
109
- client_code: sap_client.CLIENTID,
110
- name: sap_client.CLIENTDESC,
111
- local_name: sap_client.CLIENTDESCF ? sap_client.CLIENTDESCF : undefined,
112
- city: sap_client.CLIENTCITY,
113
- state: sap_client.CLIENTCOUNTY,
114
- country: sap_client.CLIENTCOUNTRY,
115
- contact_name: sap_client.CLIENTCONTACTPERSON,
116
- phone: sap_client.CLIENTPHONE1,
117
- cell_phone: sap_client.CLIENTPHONE2,
118
- comment: sap_client.CLIENTNOTE,
119
- formatted_address: sap_client.CLIENTADDRESSID,
120
- tags: tag ? [tag._id] : [],
121
- credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
122
- ? credit_limit && Math.round(credit_limit * 1000)
123
- : 1000000000,
124
- financials: {
125
- credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
126
- ? credit_limit && Math.round(credit_limit * 1000)
127
- : 1000000000,
128
- },
129
- channel: channel ? channel._id : undefined,
130
- paymentTerm: paymentTerm ? paymentTerm._id : undefined,
131
- sv_priceList: priceList ? priceList._id : undefined,
132
- disabled: sap_client.ACTIVE == "Y" ? false : true,
133
- payment_type: sap_client.PAYMENTTERM ? "credit" : "cash",
134
- integrated_client_balance: client_credit_consumed && Math.round(client_credit_consumed * 1000),
135
- };
136
- if (!repzo_client) {
137
- // Create
138
- try {
139
- const created_client = await repzo.client.create(body);
140
- result.created++;
141
- }
142
- catch (e) {
143
- // console.log("Create Client Failed >> ", e?.response, body);
144
- failed_docs_report.push({
145
- method: "create",
146
- doc: body,
147
- error_message: set_error(e),
148
- });
149
- result.failed++;
150
- }
151
- }
152
- else {
153
- const repzo_original_doc = await repzo.client.get(repzo_client._id);
154
- // console.log("match", is_matched(body, repzo_original_doc));
155
- if (is_matched(body, repzo_original_doc)) {
156
- continue;
157
- }
158
- // Update
159
- try {
160
- const updated_client = await repzo.client.update(repzo_client._id, body);
161
- result.updated++;
162
- }
163
- catch (e) {
164
- // console.log("Update Client Failed >> ", e?.response?.data, body);
165
- failed_docs_report.push({
166
- method: "update",
167
- doc_id: repzo_client === null || repzo_client === void 0 ? void 0 : repzo_client._id,
168
- doc: body,
169
- error_message: set_error(e),
170
- });
171
- result.failed++;
172
- }
173
- }
183
+ let parent;
184
+ if (sap_client.PARENTCODE) {
185
+ parent = sap_all_clients.find(
186
+ (c) => c.CLIENTID == sap_client.PARENTCODE
187
+ );
188
+ }
189
+ const credit_limit = parent
190
+ ? parent.CLIENTCREDITLIMIT
191
+ : sap_client.CLIENTCREDITLIMIT;
192
+ const client_credit_consumed = parent
193
+ ? parent.CLIENTCREDITCONSUMED
194
+ : sap_client.CLIENTCREDITCONSUMED;
195
+ const body = {
196
+ integration_meta: {
197
+ id: `${nameSpace}_${sap_client.CLIENTID}`,
198
+ PAYMENTTERM: sap_client.PAYMENTTERM,
199
+ CLIENTCREDITCONSUMED: parent
200
+ ? parent.CLIENTCREDITCONSUMED
201
+ : sap_client.CLIENTCREDITCONSUMED,
202
+ CLIENTMAXCHEQUEVALUE: parent
203
+ ? parent.CLIENTMAXCHEQUEVALUE
204
+ : sap_client.CLIENTMAXCHEQUEVALUE,
205
+ CLIENTCREDITLIMIT: parent
206
+ ? parent.CLIENTCREDITLIMIT
207
+ : sap_client.CLIENTCREDITLIMIT,
208
+ CLIENTPRICELISTID: sap_client.CLIENTPRICELISTID,
209
+ },
210
+ client_code: sap_client.CLIENTID,
211
+ name: sap_client.CLIENTDESC,
212
+ local_name: sap_client.CLIENTDESCF ? sap_client.CLIENTDESCF : undefined,
213
+ city: sap_client.CLIENTCITY,
214
+ state: sap_client.CLIENTCOUNTY,
215
+ country: sap_client.CLIENTCOUNTRY,
216
+ contact_name: sap_client.CLIENTCONTACTPERSON,
217
+ phone: sap_client.CLIENTPHONE1,
218
+ cell_phone: sap_client.CLIENTPHONE2,
219
+ comment: sap_client.CLIENTNOTE,
220
+ formatted_address: sap_client.CLIENTADDRESSID,
221
+ tags: tag ? [tag._id] : [],
222
+ credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
223
+ ? credit_limit && Math.round(credit_limit * 1000)
224
+ : 1000000000,
225
+ financials: {
226
+ credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
227
+ ? credit_limit && Math.round(credit_limit * 1000)
228
+ : 1000000000,
229
+ },
230
+ channel: channel ? channel._id : undefined,
231
+ paymentTerm: paymentTerm ? paymentTerm._id : undefined,
232
+ sv_priceList: priceList ? priceList._id : undefined,
233
+ disabled: sap_client.ACTIVE == "Y" ? false : true,
234
+ payment_type: sap_client.PAYMENTTERM ? "credit" : "cash",
235
+ integrated_client_balance:
236
+ client_credit_consumed && Math.round(client_credit_consumed * 1000),
237
+ };
238
+ if (!repzo_client) {
239
+ // Create
240
+ try {
241
+ const created_client = await repzo.client.create(body);
242
+ result.created++;
243
+ } catch (e) {
244
+ // console.log("Create Client Failed >> ", e?.response, body);
245
+ failed_docs_report.push({
246
+ method: "create",
247
+ doc: body,
248
+ error_message: set_error(e),
249
+ });
250
+ result.failed++;
174
251
  }
175
- // console.log(result);
176
- await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
177
- await commandLog
178
- .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
179
- .setBody(result)
180
- .commit();
181
- return result;
182
- }
183
- catch (e) {
184
- //@ts-ignore
185
- console.error(((_h = e === null || e === void 0 ? void 0 : e.response) === null || _h === void 0 ? void 0 : _h.data) || e);
186
- await commandLog.setStatus("fail", e).commit();
187
- throw e;
252
+ } else {
253
+ const repzo_original_doc = await repzo.client.get(repzo_client._id);
254
+ // console.log("match", is_matched(body, repzo_original_doc));
255
+ if (is_matched(body, repzo_original_doc)) {
256
+ continue;
257
+ }
258
+ // Update
259
+ try {
260
+ const updated_client = await repzo.client.update(
261
+ repzo_client._id,
262
+ body
263
+ );
264
+ result.updated++;
265
+ } catch (e) {
266
+ // console.log("Update Client Failed >> ", e?.response?.data, body);
267
+ failed_docs_report.push({
268
+ method: "update",
269
+ doc_id:
270
+ repzo_client === null || repzo_client === void 0
271
+ ? void 0
272
+ : repzo_client._id,
273
+ doc: body,
274
+ error_message: set_error(e),
275
+ });
276
+ result.failed++;
277
+ }
278
+ }
188
279
  }
280
+ // console.log(result);
281
+ await update_bench_time(
282
+ repzo,
283
+ commandEvent.app._id,
284
+ bench_time_key,
285
+ new_bench_time
286
+ );
287
+ await commandLog
288
+ .setStatus(
289
+ "success",
290
+ failed_docs_report.length ? failed_docs_report : null
291
+ )
292
+ .setBody(result)
293
+ .commit();
294
+ return result;
295
+ } catch (e) {
296
+ //@ts-ignore
297
+ console.error(
298
+ ((_h = e === null || e === void 0 ? void 0 : e.response) === null ||
299
+ _h === void 0
300
+ ? void 0
301
+ : _h.data) || e
302
+ );
303
+ await commandLog.setStatus("fail", e).commit();
304
+ throw e;
305
+ }
189
306
  };
190
307
  const get_sap_clients = async (serviceEndPoint, query) => {
191
- try {
192
- const sap_clients = await _create(serviceEndPoint, "/Customers", {
193
- Active: "Y",
194
- Frozen: "N",
195
- UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
196
- GroupCode: (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
197
- });
198
- return sap_clients.Customers;
199
- }
200
- catch (e) {
201
- throw e;
202
- }
308
+ try {
309
+ const sap_clients = await _create(serviceEndPoint, "/Customers", {
310
+ Active: "Y",
311
+ Frozen: "N",
312
+ UpdateAt: date_formatting(
313
+ query === null || query === void 0 ? void 0 : query.updateAt,
314
+ "YYYYMMDD:HHmmss"
315
+ ),
316
+ GroupCode:
317
+ (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
318
+ });
319
+ return sap_clients.Customers;
320
+ } catch (e) {
321
+ throw e;
322
+ }
203
323
  };
204
324
  const is_matched = (body_1, body_2) => {
205
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
206
- try {
207
- const keys = [
208
- "client_code",
209
- "name",
210
- "local_name",
211
- "city",
212
- "state",
213
- "country",
214
- "contact_name",
215
- "phone",
216
- "cell_phone",
217
- "comment",
218
- "formatted_address",
219
- "tags",
220
- "credit_limit",
221
- // "financials",
222
- "channel",
223
- "paymentTerm",
224
- "sv_priceList",
225
- "disabled",
226
- "payment_type",
227
- "integrated_client_balance",
228
- ];
229
- const integration_meta_keys = [
230
- "id",
231
- "PAYMENTTERM",
232
- "CLIENTCREDITCONSUMED",
233
- "CLIENTMAXCHEQUEVALUE",
234
- "CLIENTCREDITLIMIT",
235
- "CLIENTPRICELISTID",
236
- ];
237
- for (let i = 0; i < keys.length; i++) {
238
- const key = keys[i];
239
- if (((_a = body_1[key]) === null || _a === void 0 ? void 0 : _a.toString()) !== ((_b = body_2[key]) === null || _b === void 0 ? void 0 : _b.toString())) {
240
- return false;
241
- }
242
- }
243
- for (let i = 0; i < integration_meta_keys.length; i++) {
244
- const key = keys[i];
245
- if (((_d = (_c = body_1 === null || body_1 === void 0 ? void 0 : body_1.integration_meta) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.toString()) !==
246
- ((_f = (_e = body_2 === null || body_2 === void 0 ? void 0 : body_2.integration_meta) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.toString())) {
247
- return false;
248
- }
249
- }
250
- if (((_h = (_g = body_1 === null || body_1 === void 0 ? void 0 : body_1.integration_meta) === null || _g === void 0 ? void 0 : _g["financials"]) === null || _h === void 0 ? void 0 : _h.credit_limit) !==
251
- ((_k = (_j = body_2 === null || body_2 === void 0 ? void 0 : body_2.integration_meta) === null || _j === void 0 ? void 0 : _j["financials"]) === null || _k === void 0 ? void 0 : _k.credit_limit)) {
252
- return false;
253
- }
254
- return true;
325
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
326
+ try {
327
+ const keys = [
328
+ "client_code",
329
+ "name",
330
+ "local_name",
331
+ "city",
332
+ "state",
333
+ "country",
334
+ "contact_name",
335
+ "phone",
336
+ "cell_phone",
337
+ "comment",
338
+ "formatted_address",
339
+ "tags",
340
+ "credit_limit",
341
+ // "financials",
342
+ "channel",
343
+ "paymentTerm",
344
+ "sv_priceList",
345
+ "disabled",
346
+ "payment_type",
347
+ "integrated_client_balance",
348
+ ];
349
+ const integration_meta_keys = [
350
+ "id",
351
+ "PAYMENTTERM",
352
+ "CLIENTCREDITCONSUMED",
353
+ "CLIENTMAXCHEQUEVALUE",
354
+ "CLIENTCREDITLIMIT",
355
+ "CLIENTPRICELISTID",
356
+ ];
357
+ for (let i = 0; i < keys.length; i++) {
358
+ const key = keys[i];
359
+ if (
360
+ ((_a = body_1[key]) === null || _a === void 0
361
+ ? void 0
362
+ : _a.toString()) !==
363
+ ((_b = body_2[key]) === null || _b === void 0 ? void 0 : _b.toString())
364
+ ) {
365
+ return false;
366
+ }
367
+ }
368
+ for (let i = 0; i < integration_meta_keys.length; i++) {
369
+ const key = keys[i];
370
+ if (
371
+ ((_d =
372
+ (_c =
373
+ body_1 === null || body_1 === void 0
374
+ ? void 0
375
+ : body_1.integration_meta) === null || _c === void 0
376
+ ? void 0
377
+ : _c[key]) === null || _d === void 0
378
+ ? void 0
379
+ : _d.toString()) !==
380
+ ((_f =
381
+ (_e =
382
+ body_2 === null || body_2 === void 0
383
+ ? void 0
384
+ : body_2.integration_meta) === null || _e === void 0
385
+ ? void 0
386
+ : _e[key]) === null || _f === void 0
387
+ ? void 0
388
+ : _f.toString())
389
+ ) {
390
+ return false;
391
+ }
255
392
  }
256
- catch (e) {
257
- throw e;
393
+ if (
394
+ ((_h =
395
+ (_g =
396
+ body_1 === null || body_1 === void 0
397
+ ? void 0
398
+ : body_1.integration_meta) === null || _g === void 0
399
+ ? void 0
400
+ : _g["financials"]) === null || _h === void 0
401
+ ? void 0
402
+ : _h.credit_limit) !==
403
+ ((_k =
404
+ (_j =
405
+ body_2 === null || body_2 === void 0
406
+ ? void 0
407
+ : body_2.integration_meta) === null || _j === void 0
408
+ ? void 0
409
+ : _j["financials"]) === null || _k === void 0
410
+ ? void 0
411
+ : _k.credit_limit)
412
+ ) {
413
+ return false;
258
414
  }
415
+ return true;
416
+ } catch (e) {
417
+ throw e;
418
+ }
259
419
  };