repzo-sap-absjo 1.0.18 → 1.0.20

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 (75) hide show
  1. package/lib/actions/create_invoice.d.ts +13 -19
  2. package/lib/actions/create_invoice.js +207 -365
  3. package/lib/actions/create_payment.d.ts +1 -4
  4. package/lib/actions/create_payment.js +107 -195
  5. package/lib/actions/create_proforma.d.ts +1 -4
  6. package/lib/actions/create_proforma.js +146 -285
  7. package/lib/actions/create_return_invoice.d.ts +1 -4
  8. package/lib/actions/create_return_invoice.js +158 -312
  9. package/lib/actions/create_transfer.d.ts +1 -4
  10. package/lib/actions/create_transfer.js +126 -223
  11. package/lib/actions/index.js +15 -23
  12. package/lib/commands/adjust_inventory.d.ts +2 -4
  13. package/lib/commands/adjust_inventory.js +160 -290
  14. package/lib/commands/bank.d.ts +2 -4
  15. package/lib/commands/bank.js +157 -279
  16. package/lib/commands/basic.js +48 -67
  17. package/lib/commands/brand.d.ts +1 -3
  18. package/lib/commands/brand.js +100 -174
  19. package/lib/commands/category.d.ts +1 -3
  20. package/lib/commands/category.js +104 -178
  21. package/lib/commands/channel.d.ts +1 -3
  22. package/lib/commands/channel.js +117 -198
  23. package/lib/commands/client.d.ts +32 -34
  24. package/lib/commands/client.js +244 -404
  25. package/lib/commands/client_disabled.d.ts +1 -3
  26. package/lib/commands/client_disabled.js +94 -163
  27. package/lib/commands/index.d.ts +11 -15
  28. package/lib/commands/index.js +62 -62
  29. package/lib/commands/join.js +66 -192
  30. package/lib/commands/measureunit.d.ts +14 -19
  31. package/lib/commands/measureunit.js +191 -289
  32. package/lib/commands/measureunit_family.d.ts +8 -10
  33. package/lib/commands/measureunit_family.js +138 -250
  34. package/lib/commands/payment_term.d.ts +1 -3
  35. package/lib/commands/payment_term.js +123 -202
  36. package/lib/commands/price_list.d.ts +15 -15
  37. package/lib/commands/price_list.js +326 -612
  38. package/lib/commands/product.d.ts +30 -32
  39. package/lib/commands/product.js +263 -485
  40. package/lib/commands/product_disabled.d.ts +1 -3
  41. package/lib/commands/product_disabled.js +94 -160
  42. package/lib/commands/rep.js +141 -221
  43. package/lib/commands/tag.js +109 -174
  44. package/lib/commands/tax.js +112 -177
  45. package/lib/commands/warehouse.d.ts +1 -3
  46. package/lib/commands/warehouse.js +119 -207
  47. package/lib/index.d.ts +12 -21
  48. package/lib/test/actions/create_invoice.js +188 -193
  49. package/lib/test/actions/create_payment.js +107 -112
  50. package/lib/test/actions/create_proforma.js +216 -220
  51. package/lib/test/actions/create_return_invoice.js +200 -205
  52. package/lib/test/actions/create_transfer.js +115 -120
  53. package/lib/test/commands/adjust_inventory.js +90 -90
  54. package/lib/test/commands/bank.js +90 -90
  55. package/lib/test/commands/basic.js +327 -328
  56. package/lib/test/commands/brand.js +90 -90
  57. package/lib/test/commands/category.js +90 -90
  58. package/lib/test/commands/channel.js +90 -90
  59. package/lib/test/commands/client.js +353 -355
  60. package/lib/test/commands/client_disabled.js +90 -90
  61. package/lib/test/commands/join.js +327 -328
  62. package/lib/test/commands/measureunit.js +90 -90
  63. package/lib/test/commands/measureunit_family.js +90 -90
  64. package/lib/test/commands/payment_term.js +90 -90
  65. package/lib/test/commands/price_list.js +334 -337
  66. package/lib/test/commands/product.js +90 -90
  67. package/lib/test/commands/product_disabled.js +90 -90
  68. package/lib/test/commands/rep.js +344 -346
  69. package/lib/test/commands/tag.js +90 -90
  70. package/lib/test/commands/tax.js +90 -90
  71. package/lib/test/commands/warehouse.js +90 -90
  72. package/lib/types.d.ts +53 -77
  73. package/lib/util.d.ts +19 -70
  74. package/lib/util.js +144 -170
  75. package/package.json +1 -1
@@ -1,504 +1,282 @@
1
1
  import Repzo from "repzo";
2
- import {
3
- _create,
4
- update_bench_time,
5
- date_formatting,
6
- set_error,
7
- } from "../util.js";
2
+ import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
8
3
  export const sync_product = async (commandEvent) => {
9
- var _a,
10
- _b,
11
- _c,
12
- _d,
13
- _e,
14
- _f,
15
- _g,
16
- _h,
17
- _j,
18
- _k,
19
- _l,
20
- _m,
21
- _o,
22
- _p,
23
- _q,
24
- _r,
25
- _s,
26
- _t,
27
- _u;
28
- const repzo = new Repzo(
29
- (_a = commandEvent.app.formData) === null || _a === void 0
30
- ? void 0
31
- : _a.repzoApiKey,
32
- {
33
- env: commandEvent.env,
34
- }
35
- );
36
- const commandLog = new Repzo.CommandLog(
37
- repzo,
38
- commandEvent.app,
39
- commandEvent.command
40
- );
41
- try {
42
- // console.log("sync_product");
43
- const new_bench_time = new Date().toISOString();
44
- const bench_time_key = "bench_time_product";
45
- await commandLog.load(commandEvent.sync_id);
46
- await commandLog.addDetail("Repzo SAP: Started Syncing Products").commit();
47
- const nameSpace = commandEvent.nameSpace.join("_");
48
- const result = {
49
- sap_total: 0,
50
- repzo_total: 0,
51
- created: 0,
52
- updated: 0,
53
- failed: 0,
54
- repzo_total_taxes: 0,
55
- repzo_total_categories: 0,
56
- repzo_total_brands: 0,
57
- };
58
- const failed_docs_report = [];
59
- const sap_products = await get_sap_products(
60
- commandEvent.app.formData.sapHostUrl,
61
- { updateAt: commandEvent.app.options_formData[bench_time_key] }
62
- );
63
- result.sap_total =
64
- sap_products === null || sap_products === void 0
65
- ? void 0
66
- : sap_products.length;
67
- await commandLog
68
- .addDetail(
69
- `${result.sap_total} Items in SAP changed since ${
70
- commandEvent.app.options_formData[bench_time_key] || "ever"
71
- }`
72
- )
73
- .commit();
74
- // Product Repzo
75
- const repzo_products = await repzo.product.find({
76
- per_page: 50000,
77
- withVariants: true,
78
- });
79
- result.repzo_total =
80
- (_b =
81
- repzo_products === null || repzo_products === void 0
82
- ? void 0
83
- : repzo_products.data) === null || _b === void 0
84
- ? void 0
85
- : _b.length;
86
- await commandLog
87
- .addDetail(
88
- `${
89
- (_c =
90
- repzo_products === null || repzo_products === void 0
91
- ? void 0
92
- : repzo_products.data) === null || _c === void 0
93
- ? void 0
94
- : _c.length
95
- } Products in Repzo`
96
- )
97
- .commit();
98
- // Tax
99
- const repzo_taxes = await repzo.tax.find({
100
- per_page: 50000,
101
- disabled: false,
102
- });
103
- result.repzo_total_taxes =
104
- (_d =
105
- repzo_taxes === null || repzo_taxes === void 0
106
- ? void 0
107
- : repzo_taxes.data) === null || _d === void 0
108
- ? void 0
109
- : _d.length;
110
- await commandLog
111
- .addDetail(`${result.repzo_total_taxes} Taxes in Repzo`)
112
- .commit();
113
- // Category
114
- const repzo_categories = await repzo.category.find({
115
- per_page: 50000,
116
- disabled: false,
117
- });
118
- result.repzo_total_categories =
119
- (_e =
120
- repzo_categories === null || repzo_categories === void 0
121
- ? void 0
122
- : repzo_categories.data) === null || _e === void 0
123
- ? void 0
124
- : _e.length;
125
- await commandLog
126
- .addDetail(`${result.repzo_total_categories} Product Categories in Repzo`)
127
- .commit();
128
- // Brand
129
- const repzo_brands = await repzo.brand.find({
130
- per_page: 50000,
131
- disabled: false,
4
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
5
+ const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
6
+ env: commandEvent.env,
132
7
  });
133
- result.repzo_total_brands =
134
- (_f =
135
- repzo_brands === null || repzo_brands === void 0
136
- ? void 0
137
- : repzo_brands.data) === null || _f === void 0
138
- ? void 0
139
- : _f.length;
140
- await commandLog
141
- .addDetail(`${result.repzo_total_brands} Brands in Repzo`)
142
- .commit();
143
- for (
144
- let i = 0;
145
- i <
146
- (sap_products === null || sap_products === void 0
147
- ? void 0
148
- : sap_products.length);
149
- i++
150
- ) {
151
- const sap_product = sap_products[i];
152
- try {
153
- const repzo_product = repzo_products.data.find((r_product) => {
154
- var _a;
155
- return (
156
- ((_a =
157
- r_product === null || r_product === void 0
158
- ? void 0
159
- : r_product.integration_meta) === null || _a === void 0
160
- ? void 0
161
- : _a.id) == `${nameSpace}_${sap_product.ITEMCODE}`
162
- );
8
+ const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
9
+ try {
10
+ // console.log("sync_product");
11
+ const new_bench_time = new Date().toISOString();
12
+ const bench_time_key = "bench_time_product";
13
+ await commandLog.load(commandEvent.sync_id);
14
+ await commandLog.addDetail("Repzo SAP: Started Syncing Products").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
+ repzo_total_taxes: 0,
23
+ repzo_total_categories: 0,
24
+ repzo_total_brands: 0,
25
+ };
26
+ const failed_docs_report = [];
27
+ const sap_products = await get_sap_products(commandEvent.app.formData.sapHostUrl, { updateAt: commandEvent.app.options_formData[bench_time_key] });
28
+ result.sap_total = sap_products === null || sap_products === void 0 ? void 0 : sap_products.length;
29
+ await commandLog
30
+ .addDetail(`${result.sap_total} Items in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
31
+ .commit();
32
+ // Product Repzo
33
+ const repzo_products = await repzo.product.find({
34
+ per_page: 50000,
35
+ withVariants: true,
163
36
  });
37
+ result.repzo_total = (_b = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _b === void 0 ? void 0 : _b.length;
38
+ await commandLog
39
+ .addDetail(`${(_c = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _c === void 0 ? void 0 : _c.length} Products in Repzo`)
40
+ .commit();
164
41
  // Tax
165
- const tax =
166
- (_g =
167
- repzo_taxes === null || repzo_taxes === void 0
168
- ? void 0
169
- : repzo_taxes.data) === null || _g === void 0
170
- ? void 0
171
- : _g.find((tax) => {
172
- var _a;
173
- return (
174
- ((_a =
175
- tax === null || tax === void 0
176
- ? void 0
177
- : tax.integration_meta) === null || _a === void 0
178
- ? void 0
179
- : _a.id) == `${nameSpace}_${sap_product.ITEMTAXCODE}`
180
- );
181
- });
182
- if (!tax) {
183
- throw `Tax not found => ITEMTAXCODE: ${sap_product.ITEMTAXCODE}`;
184
- continue;
185
- }
186
- const product_tax =
187
- (_h = tax === null || tax === void 0 ? void 0 : tax._id) === null ||
188
- _h === void 0
189
- ? void 0
190
- : _h.toString();
42
+ const repzo_taxes = await repzo.tax.find({
43
+ per_page: 50000,
44
+ disabled: false,
45
+ });
46
+ result.repzo_total_taxes = (_d = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _d === void 0 ? void 0 : _d.length;
47
+ await commandLog
48
+ .addDetail(`${result.repzo_total_taxes} Taxes in Repzo`)
49
+ .commit();
191
50
  // Category
192
- const category =
193
- (_j =
194
- repzo_categories === null || repzo_categories === void 0
195
- ? void 0
196
- : repzo_categories.data) === null || _j === void 0
197
- ? void 0
198
- : _j.find((category) => {
199
- var _a;
200
- return (
201
- ((_a =
202
- category === null || category === void 0
203
- ? void 0
204
- : category.integration_meta) === null || _a === void 0
205
- ? void 0
206
- : _a.id) == `${nameSpace}_${sap_product.ITEMGROUPCODE}`
207
- );
208
- });
209
- if (!category) {
210
- throw `Category not found => ITEMGROUPCODE: ${sap_product.ITEMGROUPCODE}`;
211
- continue;
212
- }
213
- const product_category =
214
- (_k =
215
- category === null || category === void 0
216
- ? void 0
217
- : category._id) === null || _k === void 0
218
- ? void 0
219
- : _k.toString();
220
- // Brand
221
- const brand =
222
- (_l =
223
- repzo_brands === null || repzo_brands === void 0
224
- ? void 0
225
- : repzo_brands.data) === null || _l === void 0
226
- ? void 0
227
- : _l.find((brand) => {
228
- var _a;
229
- return (
230
- ((_a =
231
- brand === null || brand === void 0
232
- ? void 0
233
- : brand.integration_meta) === null || _a === void 0
234
- ? void 0
235
- : _a.id) == `${nameSpace}_${sap_product["Parent Category"]}`
236
- );
237
- });
238
- const product_brand =
239
- (_m = brand === null || brand === void 0 ? void 0 : brand._id) ===
240
- null || _m === void 0
241
- ? void 0
242
- : _m.toString();
243
- // measureUnit family
244
- const family = await repzo.measureunitFamily.find({
245
- "integration_meta.id": `${nameSpace}_${sap_product.ITEMCODE}`,
246
- disabled: false,
51
+ const repzo_categories = await repzo.category.find({
52
+ per_page: 50000,
53
+ disabled: false,
247
54
  });
248
- if (
249
- !(family === null || family === void 0 ? void 0 : family.data) ||
250
- ((_o =
251
- family === null || family === void 0 ? void 0 : family.data) ===
252
- null || _o === void 0
253
- ? void 0
254
- : _o.length) != 1
255
- ) {
256
- throw `Family not found => ITEMCODE: ${sap_product.ITEMCODE}`;
257
- continue;
258
- }
259
- const product_family =
260
- (_q =
261
- (_p = family.data[0]) === null || _p === void 0
262
- ? void 0
263
- : _p._id) === null || _q === void 0
264
- ? void 0
265
- : _q.toString();
266
- // measureUnit
267
- const measureUnit = await repzo.measureunit.find({
268
- "integration_meta.UOMGROUPENTRY": sap_product.UOMGROUPENTRY,
269
- name: sap_product.DEFAULTITEMUOM,
270
- company_namespace: nameSpace,
271
- disabled: false,
55
+ result.repzo_total_categories = (_e = repzo_categories === null || repzo_categories === void 0 ? void 0 : repzo_categories.data) === null || _e === void 0 ? void 0 : _e.length;
56
+ await commandLog
57
+ .addDetail(`${result.repzo_total_categories} Product Categories in Repzo`)
58
+ .commit();
59
+ // Brand
60
+ const repzo_brands = await repzo.brand.find({
61
+ per_page: 50000,
62
+ disabled: false,
272
63
  });
273
- if (!measureUnit.data || measureUnit.data.length != 1) {
274
- throw `MeasureUnit not found => UOMGROUPENTRY: ${sap_product.UOMGROUPENTRY}, ITEMCODE: ${sap_product.ITEMCODE}, DEFAULTITEMUOM: ${sap_product.DEFAULTITEMUOM}`;
275
- continue;
276
- }
277
- const product_measureUnit =
278
- (_r = measureUnit.data[0]._id) === null || _r === void 0
279
- ? void 0
280
- : _r.toString();
281
- const body = {
282
- active: true,
283
- name: sap_product.ITEMDESC,
284
- local_name: sap_product.ITEMDESCF,
285
- barcode: sap_product.ITEMBARCODE,
286
- sku: sap_product.ITEMCODE,
287
- sv_tax: product_tax,
288
- category: product_category,
289
- brand: product_brand,
290
- measureunit_family: product_family,
291
- sv_measureUnit: product_measureUnit,
292
- integration_meta: {
293
- id: `${nameSpace}_${sap_product.ITEMCODE}`,
294
- ITEMGROUPCODE: sap_product.ITEMGROUPCODE,
295
- UOMGROUPENTRY: sap_product.UOMGROUPENTRY,
296
- BRAND: sap_product.BRAND,
297
- },
298
- variants: [
299
- {
300
- disabled: false,
301
- name: sap_product.ITEMCODE,
302
- price: 0,
303
- integration_meta: {
304
- id: `${nameSpace}_${sap_product.ITEMCODE}`,
305
- ITEMCODE: sap_product.ITEMCODE,
306
- },
307
- company_namespace: [nameSpace],
308
- },
309
- ],
310
- company_namespace: [nameSpace],
311
- };
312
- if (!repzo_product) {
313
- // Create
314
- try {
315
- const created_product = await repzo.product.create(body);
316
- result.created++;
317
- } catch (e) {
318
- // console.log("Create Product Failed >> ", e?.response, body);
319
- failed_docs_report.push({
320
- method: "create",
321
- doc: body,
322
- error_message: set_error(e),
323
- });
324
- result.failed++;
325
- }
326
- } else {
327
- if (is_matched(body, repzo_product)) {
328
- continue;
329
- }
330
- if (
331
- (_s =
332
- repzo_product === null || repzo_product === void 0
333
- ? void 0
334
- : repzo_product.variants) === null || _s === void 0
335
- ? void 0
336
- : _s.length
337
- ) {
338
- (_t = body === null || body === void 0 ? void 0 : body.variants) ===
339
- null || _t === void 0
340
- ? void 0
341
- : _t.forEach((variant) => {
342
- var _a;
343
- const hasMatch =
344
- (_a =
345
- repzo_product === null || repzo_product === void 0
346
- ? void 0
347
- : repzo_product.variants) === null || _a === void 0
348
- ? void 0
349
- : _a.find((v) => {
350
- var _a, _b;
351
- return (
352
- ((_a = v.integration_meta) === null || _a === void 0
353
- ? void 0
354
- : _a.id) ==
355
- ((_b =
356
- variant === null || variant === void 0
357
- ? void 0
358
- : variant.integration_meta) === null ||
359
- _b === void 0
360
- ? void 0
361
- : _b.id)
362
- );
64
+ result.repzo_total_brands = (_f = repzo_brands === null || repzo_brands === void 0 ? void 0 : repzo_brands.data) === null || _f === void 0 ? void 0 : _f.length;
65
+ await commandLog
66
+ .addDetail(`${result.repzo_total_brands} Brands in Repzo`)
67
+ .commit();
68
+ for (let i = 0; i < (sap_products === null || sap_products === void 0 ? void 0 : sap_products.length); i++) {
69
+ const sap_product = sap_products[i];
70
+ try {
71
+ const repzo_product = repzo_products.data.find((r_product) => {
72
+ var _a;
73
+ return ((_a = r_product === null || r_product === void 0 ? void 0 : r_product.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
74
+ `${nameSpace}_${sap_product.ITEMCODE}`;
75
+ });
76
+ // Tax
77
+ const tax = (_g = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _g === void 0 ? void 0 : _g.find((tax) => {
78
+ var _a;
79
+ return ((_a = tax === null || tax === void 0 ? void 0 : tax.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
80
+ `${nameSpace}_${sap_product.ITEMTAXCODE}`;
81
+ });
82
+ if (!tax) {
83
+ throw `Tax not found => ITEMTAXCODE: ${sap_product.ITEMTAXCODE}`;
84
+ continue;
85
+ }
86
+ const product_tax = (_h = tax === null || tax === void 0 ? void 0 : tax._id) === null || _h === void 0 ? void 0 : _h.toString();
87
+ // Category
88
+ const category = (_j = repzo_categories === null || repzo_categories === void 0 ? void 0 : repzo_categories.data) === null || _j === void 0 ? void 0 : _j.find((category) => {
89
+ var _a;
90
+ return ((_a = category === null || category === void 0 ? void 0 : category.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
91
+ `${nameSpace}_${sap_product.ITEMGROUPCODE}`;
92
+ });
93
+ if (!category) {
94
+ throw `Category not found => ITEMGROUPCODE: ${sap_product.ITEMGROUPCODE}`;
95
+ continue;
96
+ }
97
+ const product_category = (_k = category === null || category === void 0 ? void 0 : category._id) === null || _k === void 0 ? void 0 : _k.toString();
98
+ // Brand
99
+ const brand = (_l = repzo_brands === null || repzo_brands === void 0 ? void 0 : repzo_brands.data) === null || _l === void 0 ? void 0 : _l.find((brand) => {
100
+ var _a;
101
+ return ((_a = brand === null || brand === void 0 ? void 0 : brand.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
102
+ `${nameSpace}_${sap_product["Parent Category"]}`;
103
+ });
104
+ const product_brand = (_m = brand === null || brand === void 0 ? void 0 : brand._id) === null || _m === void 0 ? void 0 : _m.toString();
105
+ // measureUnit family
106
+ const family = await repzo.measureunitFamily.find({
107
+ "integration_meta.id": `${nameSpace}_${sap_product.ITEMCODE}`,
108
+ disabled: false,
109
+ });
110
+ if (!(family === null || family === void 0 ? void 0 : family.data) || ((_o = family === null || family === void 0 ? void 0 : family.data) === null || _o === void 0 ? void 0 : _o.length) != 1) {
111
+ throw `Family not found => ITEMCODE: ${sap_product.ITEMCODE}`;
112
+ continue;
113
+ }
114
+ const product_family = (_q = (_p = family.data[0]) === null || _p === void 0 ? void 0 : _p._id) === null || _q === void 0 ? void 0 : _q.toString();
115
+ // measureUnit
116
+ const measureUnit = await repzo.measureunit.find({
117
+ "integration_meta.UOMGROUPENTRY": sap_product.UOMGROUPENTRY,
118
+ name: sap_product.DEFAULTITEMUOM,
119
+ company_namespace: nameSpace,
120
+ disabled: false,
121
+ });
122
+ if (!measureUnit.data || measureUnit.data.length != 1) {
123
+ throw `MeasureUnit not found => UOMGROUPENTRY: ${sap_product.UOMGROUPENTRY}, ITEMCODE: ${sap_product.ITEMCODE}, DEFAULTITEMUOM: ${sap_product.DEFAULTITEMUOM}`;
124
+ continue;
125
+ }
126
+ const product_measureUnit = (_r = measureUnit.data[0]._id) === null || _r === void 0 ? void 0 : _r.toString();
127
+ const body = {
128
+ active: true,
129
+ name: sap_product.ITEMDESC,
130
+ local_name: sap_product.ITEMDESCF,
131
+ barcode: sap_product.ITEMBARCODE,
132
+ sku: sap_product.ITEMCODE,
133
+ sv_tax: product_tax,
134
+ category: product_category,
135
+ brand: product_brand,
136
+ measureunit_family: product_family,
137
+ sv_measureUnit: product_measureUnit,
138
+ integration_meta: {
139
+ id: `${nameSpace}_${sap_product.ITEMCODE}`,
140
+ ITEMGROUPCODE: sap_product.ITEMGROUPCODE,
141
+ UOMGROUPENTRY: sap_product.UOMGROUPENTRY,
142
+ BRAND: sap_product.BRAND,
143
+ },
144
+ variants: [
145
+ {
146
+ disabled: false,
147
+ name: sap_product.ITEMCODE,
148
+ price: 0,
149
+ integration_meta: {
150
+ id: `${nameSpace}_${sap_product.ITEMCODE}`,
151
+ ITEMCODE: sap_product.ITEMCODE,
152
+ },
153
+ company_namespace: [nameSpace],
154
+ },
155
+ ],
156
+ company_namespace: [nameSpace],
157
+ };
158
+ if (!repzo_product) {
159
+ // Create
160
+ try {
161
+ const created_product = await repzo.product.create(body);
162
+ result.created++;
163
+ }
164
+ catch (e) {
165
+ // console.log("Create Product Failed >> ", e?.response, body);
166
+ failed_docs_report.push({
167
+ method: "create",
168
+ doc: body,
169
+ error_message: set_error(e),
363
170
  });
364
- if (hasMatch) {
365
- variant._id = hasMatch._id;
366
- }
171
+ result.failed++;
172
+ }
173
+ }
174
+ else {
175
+ if (is_matched(body, repzo_product)) {
176
+ continue;
177
+ }
178
+ if ((_s = repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product.variants) === null || _s === void 0 ? void 0 : _s.length) {
179
+ (_t = body === null || body === void 0 ? void 0 : body.variants) === null || _t === void 0 ? void 0 : _t.forEach((variant) => {
180
+ var _a;
181
+ const hasMatch = (_a = repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product.variants) === null || _a === void 0 ? void 0 : _a.find((v) => { var _a, _b; return ((_a = v.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == ((_b = variant === null || variant === void 0 ? void 0 : variant.integration_meta) === null || _b === void 0 ? void 0 : _b.id); });
182
+ if (hasMatch) {
183
+ variant._id = hasMatch._id;
184
+ }
185
+ });
186
+ }
187
+ // Update
188
+ try {
189
+ const updated_product = await repzo.product.update(repzo_product._id, body);
190
+ result.updated++;
191
+ }
192
+ catch (e) {
193
+ // console.log("Update Product Failed >> ", e?.response?.data, body);
194
+ failed_docs_report.push({
195
+ method: "update",
196
+ doc_id: repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product._id,
197
+ doc: body,
198
+ error_message: set_error(e),
199
+ });
200
+ result.failed++;
201
+ }
202
+ }
203
+ }
204
+ catch (e) {
205
+ // console.log("FetchingData Product Failed >> ", e);
206
+ failed_docs_report.push({
207
+ method: "fetchingData",
208
+ doc_id: sap_product.ITEMBARCODE,
209
+ error_message: set_error(e),
367
210
  });
368
- }
369
- // Update
370
- try {
371
- const updated_product = await repzo.product.update(
372
- repzo_product._id,
373
- body
374
- );
375
- result.updated++;
376
- } catch (e) {
377
- // console.log("Update Product Failed >> ", e?.response?.data, body);
378
- failed_docs_report.push({
379
- method: "update",
380
- doc_id:
381
- repzo_product === null || repzo_product === void 0
382
- ? void 0
383
- : repzo_product._id,
384
- doc: body,
385
- error_message: set_error(e),
386
- });
387
- result.failed++;
388
- }
211
+ result.failed++;
212
+ }
389
213
  }
390
- } catch (e) {
391
- // console.log("FetchingData Product Failed >> ", e);
392
- failed_docs_report.push({
393
- method: "fetchingData",
394
- doc_id: sap_product.ITEMBARCODE,
395
- error_message: set_error(e),
396
- });
397
- result.failed++;
398
- }
214
+ // console.log(result);
215
+ await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
216
+ await commandLog
217
+ .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
218
+ .setBody(result)
219
+ .commit();
220
+ return result;
221
+ }
222
+ catch (e) {
223
+ //@ts-ignore
224
+ console.error(((_u = e === null || e === void 0 ? void 0 : e.response) === null || _u === void 0 ? void 0 : _u.data) || e);
225
+ await commandLog.setStatus("fail", e).commit();
226
+ throw e;
399
227
  }
400
- // console.log(result);
401
- await update_bench_time(
402
- repzo,
403
- commandEvent.app._id,
404
- bench_time_key,
405
- new_bench_time
406
- );
407
- await commandLog
408
- .setStatus(
409
- "success",
410
- failed_docs_report.length ? failed_docs_report : null
411
- )
412
- .setBody(result)
413
- .commit();
414
- return result;
415
- } catch (e) {
416
- //@ts-ignore
417
- console.error(
418
- ((_u = e === null || e === void 0 ? void 0 : e.response) === null ||
419
- _u === void 0
420
- ? void 0
421
- : _u.data) || e
422
- );
423
- await commandLog.setStatus("fail", e).commit();
424
- throw e;
425
- }
426
228
  };
427
229
  const get_sap_products = async (serviceEndPoint, query) => {
428
- try {
429
- const sap_products = await _create(serviceEndPoint, "/Items", {
430
- Active: "Y",
431
- UpdateAt: date_formatting(
432
- query === null || query === void 0 ? void 0 : query.updateAt,
433
- "YYYYMMDD:HHmmss"
434
- ),
435
- });
436
- return sap_products.Items;
437
- } catch (e) {
438
- throw e;
439
- }
230
+ try {
231
+ const sap_products = await _create(serviceEndPoint, "/Items", {
232
+ Active: "Y",
233
+ UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
234
+ });
235
+ return sap_products.Items;
236
+ }
237
+ catch (e) {
238
+ throw e;
239
+ }
440
240
  };
441
241
  const is_matched = (body_1, body_2) => {
442
- var _a, _b, _c, _d, _e, _f;
443
- try {
444
- const keys = [
445
- "active",
446
- "name",
447
- "local_name",
448
- "barcode",
449
- "sku",
450
- "sv_tax",
451
- "category",
452
- "measureunit_family",
453
- "sv_measureUnit",
454
- "brand",
455
- ];
456
- const integration_meta_keys = [
457
- "id",
458
- "ITEMGROUPCODE",
459
- "UOMGROUPENTRY",
460
- "BRAND",
461
- ];
462
- const variant_keys = ["variants", "disabled", "name", "price"];
463
- const variant_integration_meta_keys = ["integration_meta.id"];
464
- for (let i = 0; i < keys.length; i++) {
465
- const key = keys[i];
466
- if (
467
- ((_a = body_1[key]) === null || _a === void 0
468
- ? void 0
469
- : _a.toString()) !==
470
- ((_b = body_2[key]) === null || _b === void 0 ? void 0 : _b.toString())
471
- ) {
472
- return false;
473
- }
242
+ var _a, _b, _c, _d, _e, _f;
243
+ try {
244
+ const keys = [
245
+ "active",
246
+ "name",
247
+ "local_name",
248
+ "barcode",
249
+ "sku",
250
+ "sv_tax",
251
+ "category",
252
+ "measureunit_family",
253
+ "sv_measureUnit",
254
+ "brand",
255
+ ];
256
+ const integration_meta_keys = [
257
+ "id",
258
+ "ITEMGROUPCODE",
259
+ "UOMGROUPENTRY",
260
+ "BRAND",
261
+ ];
262
+ const variant_keys = ["variants", "disabled", "name", "price"];
263
+ const variant_integration_meta_keys = ["integration_meta.id"];
264
+ for (let i = 0; i < keys.length; i++) {
265
+ const key = keys[i];
266
+ 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())) {
267
+ return false;
268
+ }
269
+ }
270
+ for (let i = 0; i < integration_meta_keys.length; i++) {
271
+ const key = keys[i];
272
+ 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()) !==
273
+ ((_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())) {
274
+ return false;
275
+ }
276
+ }
277
+ return true;
474
278
  }
475
- for (let i = 0; i < integration_meta_keys.length; i++) {
476
- const key = keys[i];
477
- if (
478
- ((_d =
479
- (_c =
480
- body_1 === null || body_1 === void 0
481
- ? void 0
482
- : body_1.integration_meta) === null || _c === void 0
483
- ? void 0
484
- : _c[key]) === null || _d === void 0
485
- ? void 0
486
- : _d.toString()) !==
487
- ((_f =
488
- (_e =
489
- body_2 === null || body_2 === void 0
490
- ? void 0
491
- : body_2.integration_meta) === null || _e === void 0
492
- ? void 0
493
- : _e[key]) === null || _f === void 0
494
- ? void 0
495
- : _f.toString())
496
- ) {
497
- return false;
498
- }
279
+ catch (e) {
280
+ throw e;
499
281
  }
500
- return true;
501
- } catch (e) {
502
- throw e;
503
- }
504
282
  };