repzo-sap-absjo 1.0.1

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 (157) hide show
  1. package/README.md +3 -0
  2. package/changelog.md +17 -0
  3. package/lib/actions/create_invoice.d.ts +26 -0
  4. package/lib/actions/create_invoice.js +311 -0
  5. package/lib/actions/create_payment.d.ts +5 -0
  6. package/lib/actions/create_payment.js +177 -0
  7. package/lib/actions/create_proforma.d.ts +5 -0
  8. package/lib/actions/create_proforma.js +241 -0
  9. package/lib/actions/create_return_invoice.d.ts +5 -0
  10. package/lib/actions/create_return_invoice.js +268 -0
  11. package/lib/actions/create_transfer.d.ts +5 -0
  12. package/lib/actions/create_transfer.js +171 -0
  13. package/lib/actions/index.d.ts +3 -0
  14. package/lib/actions/index.js +31 -0
  15. package/lib/commands/adjust_inventory.d.ts +6 -0
  16. package/lib/commands/adjust_inventory.js +303 -0
  17. package/lib/commands/bank.d.ts +7 -0
  18. package/lib/commands/bank.js +301 -0
  19. package/lib/commands/basic.d.ts +2 -0
  20. package/lib/commands/basic.js +73 -0
  21. package/lib/commands/category.d.ts +4 -0
  22. package/lib/commands/category.js +193 -0
  23. package/lib/commands/channel.d.ts +4 -0
  24. package/lib/commands/channel.js +213 -0
  25. package/lib/commands/client.d.ts +39 -0
  26. package/lib/commands/client.js +410 -0
  27. package/lib/commands/client_disabled.d.ts +4 -0
  28. package/lib/commands/client_disabled.js +183 -0
  29. package/lib/commands/index.d.ts +23 -0
  30. package/lib/commands/index.js +82 -0
  31. package/lib/commands/join.d.ts +2 -0
  32. package/lib/commands/join.js +134 -0
  33. package/lib/commands/measureunit.d.ts +23 -0
  34. package/lib/commands/measureunit.js +314 -0
  35. package/lib/commands/measureunit_family.d.ts +12 -0
  36. package/lib/commands/measureunit_family.js +263 -0
  37. package/lib/commands/payment_term.d.ts +4 -0
  38. package/lib/commands/payment_term.js +217 -0
  39. package/lib/commands/price_list.d.ts +18 -0
  40. package/lib/commands/price_list.js +608 -0
  41. package/lib/commands/product.d.ts +39 -0
  42. package/lib/commands/product.js +454 -0
  43. package/lib/commands/product_disabled.d.ts +4 -0
  44. package/lib/commands/product_disabled.js +178 -0
  45. package/lib/commands/rep.d.ts +2 -0
  46. package/lib/commands/rep.js +246 -0
  47. package/lib/commands/tag.d.ts +2 -0
  48. package/lib/commands/tag.js +195 -0
  49. package/lib/commands/tax.d.ts +2 -0
  50. package/lib/commands/tax.js +198 -0
  51. package/lib/commands/warehouse.d.ts +4 -0
  52. package/lib/commands/warehouse.js +221 -0
  53. package/lib/index.d.ts +29 -0
  54. package/lib/index.js +6 -0
  55. package/lib/test/actions/create_invoice.d.ts +1 -0
  56. package/lib/test/actions/create_invoice.js +214 -0
  57. package/lib/test/actions/create_payment.d.ts +1 -0
  58. package/lib/test/actions/create_payment.js +131 -0
  59. package/lib/test/actions/create_proforma.d.ts +1 -0
  60. package/lib/test/actions/create_proforma.js +242 -0
  61. package/lib/test/actions/create_return_invoice.d.ts +1 -0
  62. package/lib/test/actions/create_return_invoice.js +226 -0
  63. package/lib/test/actions/create_transfer.d.ts +1 -0
  64. package/lib/test/actions/create_transfer.js +142 -0
  65. package/lib/test/commands/adjust_inventory.d.ts +1 -0
  66. package/lib/test/commands/adjust_inventory.js +97 -0
  67. package/lib/test/commands/bank.d.ts +1 -0
  68. package/lib/test/commands/bank.js +97 -0
  69. package/lib/test/commands/basic.d.ts +1 -0
  70. package/lib/test/commands/basic.js +339 -0
  71. package/lib/test/commands/category.d.ts +1 -0
  72. package/lib/test/commands/category.js +97 -0
  73. package/lib/test/commands/channel.d.ts +1 -0
  74. package/lib/test/commands/channel.js +97 -0
  75. package/lib/test/commands/client.d.ts +1 -0
  76. package/lib/test/commands/client.js +97 -0
  77. package/lib/test/commands/client_disabled.d.ts +1 -0
  78. package/lib/test/commands/client_disabled.js +97 -0
  79. package/lib/test/commands/join.d.ts +1 -0
  80. package/lib/test/commands/join.js +339 -0
  81. package/lib/test/commands/measureunit.d.ts +1 -0
  82. package/lib/test/commands/measureunit.js +97 -0
  83. package/lib/test/commands/measureunit_family.d.ts +1 -0
  84. package/lib/test/commands/measureunit_family.js +97 -0
  85. package/lib/test/commands/payment_term.d.ts +1 -0
  86. package/lib/test/commands/payment_term.js +97 -0
  87. package/lib/test/commands/price_list.d.ts +1 -0
  88. package/lib/test/commands/price_list.js +97 -0
  89. package/lib/test/commands/product.d.ts +1 -0
  90. package/lib/test/commands/product.js +97 -0
  91. package/lib/test/commands/product_disabled.d.ts +1 -0
  92. package/lib/test/commands/product_disabled.js +97 -0
  93. package/lib/test/commands/rep.d.ts +1 -0
  94. package/lib/test/commands/rep.js +97 -0
  95. package/lib/test/commands/tag.d.ts +1 -0
  96. package/lib/test/commands/tag.js +97 -0
  97. package/lib/test/commands/tax.d.ts +1 -0
  98. package/lib/test/commands/tax.js +97 -0
  99. package/lib/test/commands/warehouse.d.ts +1 -0
  100. package/lib/test/commands/warehouse.js +97 -0
  101. package/lib/types.d.ts +77 -0
  102. package/lib/types.js +1 -0
  103. package/lib/util.d.ts +70 -0
  104. package/lib/util.js +164 -0
  105. package/package.json +51 -0
  106. package/src/actions/create_invoice.ts +275 -0
  107. package/src/actions/create_payment.ts +138 -0
  108. package/src/actions/create_proforma.ts +187 -0
  109. package/src/actions/create_return_invoice.ts +217 -0
  110. package/src/actions/create_transfer.ts +160 -0
  111. package/src/actions/index.ts +27 -0
  112. package/src/commands/adjust_inventory.ts +250 -0
  113. package/src/commands/bank.ts +243 -0
  114. package/src/commands/basic.ts +64 -0
  115. package/src/commands/category.ts +176 -0
  116. package/src/commands/channel.ts +219 -0
  117. package/src/commands/client.ts +368 -0
  118. package/src/commands/client_disabled.ts +158 -0
  119. package/src/commands/index.ts +87 -0
  120. package/src/commands/join.ts +80 -0
  121. package/src/commands/measureunit.ts +276 -0
  122. package/src/commands/measureunit_family.ts +209 -0
  123. package/src/commands/payment_term.ts +224 -0
  124. package/src/commands/price_list.ts +434 -0
  125. package/src/commands/product.ts +359 -0
  126. package/src/commands/product_disabled.ts +152 -0
  127. package/src/commands/rep.ts +209 -0
  128. package/src/commands/tag.ts +173 -0
  129. package/src/commands/tax.ts +178 -0
  130. package/src/commands/warehouse.ts +204 -0
  131. package/src/index.ts +7 -0
  132. package/src/test/actions/create_invoice.ts +214 -0
  133. package/src/test/actions/create_payment.ts +131 -0
  134. package/src/test/actions/create_proforma.ts +242 -0
  135. package/src/test/actions/create_return_invoice.ts +226 -0
  136. package/src/test/actions/create_transfer.ts +142 -0
  137. package/src/test/commands/adjust_inventory.ts +100 -0
  138. package/src/test/commands/bank.ts +100 -0
  139. package/src/test/commands/basic.ts +342 -0
  140. package/src/test/commands/category.ts +100 -0
  141. package/src/test/commands/channel.ts +100 -0
  142. package/src/test/commands/client.ts +100 -0
  143. package/src/test/commands/client_disabled.ts +100 -0
  144. package/src/test/commands/join.ts +342 -0
  145. package/src/test/commands/measureunit.ts +100 -0
  146. package/src/test/commands/measureunit_family.ts +100 -0
  147. package/src/test/commands/payment_term.ts +100 -0
  148. package/src/test/commands/price_list.ts +100 -0
  149. package/src/test/commands/product.ts +100 -0
  150. package/src/test/commands/product_disabled.ts +100 -0
  151. package/src/test/commands/rep.ts +100 -0
  152. package/src/test/commands/tag.ts +100 -0
  153. package/src/test/commands/tax.ts +100 -0
  154. package/src/test/commands/warehouse.ts +100 -0
  155. package/src/types.ts +76 -0
  156. package/src/util.ts +205 -0
  157. package/tsconfig.json +15 -0
@@ -0,0 +1,31 @@
1
+ import { create_invoice } from "./create_invoice.js";
2
+ import { create_return_invoice } from "./create_return_invoice.js";
3
+ import { create_proforma } from "./create_proforma.js";
4
+ import { create_payment } from "./create_payment.js";
5
+ import { create_transfer } from "./create_transfer.js";
6
+ export const actions = async (event, options) => {
7
+ var _a, _b;
8
+ switch (
9
+ (_a = event.queryStringParameters) === null || _a === void 0
10
+ ? void 0
11
+ : _a.action
12
+ ) {
13
+ case "create_invoice":
14
+ return await create_invoice(event, options);
15
+ case "create_return_invoice":
16
+ return await create_return_invoice(event, options);
17
+ case "create_proforma":
18
+ return await create_proforma(event, options);
19
+ case "create_payment":
20
+ return await create_payment(event, options);
21
+ case "create_transfer":
22
+ return await create_transfer(event, options);
23
+ default:
24
+ throw `Route: ${
25
+ (_b = event.queryStringParameters) === null || _b === void 0
26
+ ? void 0
27
+ : _b.action
28
+ } not found`;
29
+ }
30
+ };
31
+ export const actionsList = [];
@@ -0,0 +1,6 @@
1
+ import { CommandEvent, Result } from "../types";
2
+ export declare const adjust_inventory: (commandEvent: CommandEvent) => Promise<
3
+ Result & {
4
+ items_failed: number;
5
+ }
6
+ >;
@@ -0,0 +1,303 @@
1
+ import Repzo from "repzo";
2
+ import { v4 as uuid } from "uuid";
3
+ import { _create, set_error } from "../util.js";
4
+ export const adjust_inventory = async (commandEvent) => {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
6
+ const repzo = new Repzo(
7
+ (_a = commandEvent.app.formData) === null || _a === void 0
8
+ ? void 0
9
+ : _a.repzoApiKey,
10
+ {
11
+ env: commandEvent.env,
12
+ }
13
+ );
14
+ const commandLog = new Repzo.CommandLog(
15
+ repzo,
16
+ commandEvent.app,
17
+ commandEvent.command
18
+ );
19
+ try {
20
+ console.log("adjust_inventory");
21
+ await commandLog.load(commandEvent.sync_id);
22
+ await commandLog
23
+ .addDetail("Repzo SAP: Started Adjusting Inventories")
24
+ .commit();
25
+ const nameSpace = commandEvent.nameSpace.join("_");
26
+ const result = {
27
+ sap_total: 0,
28
+ repzo_total: 0,
29
+ items_failed: 0,
30
+ created: 0,
31
+ updated: 0,
32
+ failed: 0,
33
+ };
34
+ const failed_docs_report = [];
35
+ const sap_inventories_items = await get_sap_inventories(
36
+ commandEvent.app.formData.sapHostUrl,
37
+ {}
38
+ );
39
+ result.sap_total =
40
+ sap_inventories_items === null || sap_inventories_items === void 0
41
+ ? void 0
42
+ : sap_inventories_items.length;
43
+ await commandLog
44
+ .addDetail(`${result.sap_total} Stores Balance in SAP`)
45
+ .commit();
46
+ // Get Repzo Variants
47
+ const repzo_variants = await repzo.variant.find({
48
+ per_page: 50000,
49
+ disabled: false,
50
+ withProduct: true,
51
+ });
52
+ await commandLog
53
+ .addDetail(
54
+ `${
55
+ (_b =
56
+ repzo_variants === null || repzo_variants === void 0
57
+ ? void 0
58
+ : repzo_variants.data) === null || _b === void 0
59
+ ? void 0
60
+ : _b.length
61
+ } Variant(s) in Repzo`
62
+ )
63
+ .commit();
64
+ // Get Repzo Warehouses
65
+ const repzo_warehouses = await repzo.warehouse.find({
66
+ per_page: 50000,
67
+ disabled: false,
68
+ });
69
+ await commandLog
70
+ .addDetail(
71
+ `${
72
+ (_c =
73
+ repzo_warehouses === null || repzo_warehouses === void 0
74
+ ? void 0
75
+ : repzo_warehouses.data) === null || _c === void 0
76
+ ? void 0
77
+ : _c.length
78
+ } Warehouse(s) in Repzo`
79
+ )
80
+ .commit();
81
+ // Get Repzo Measure Units
82
+ const repzo_measureunits = await repzo.measureunit.find({
83
+ per_page: 50000,
84
+ disabled: false,
85
+ });
86
+ await commandLog
87
+ .addDetail(
88
+ `${
89
+ (_d =
90
+ repzo_measureunits === null || repzo_measureunits === void 0
91
+ ? void 0
92
+ : repzo_measureunits.data) === null || _d === void 0
93
+ ? void 0
94
+ : _d.length
95
+ } Measure Unit(s) in Repzo`
96
+ )
97
+ .commit();
98
+ const repzo_tags = await repzo.tag.find({ type: "area", per_page: 50000 });
99
+ result.repzo_total =
100
+ (_e =
101
+ repzo_tags === null || repzo_tags === void 0
102
+ ? void 0
103
+ : repzo_tags.data) === null || _e === void 0
104
+ ? void 0
105
+ : _e.length;
106
+ await commandLog
107
+ .addDetail(
108
+ `${
109
+ (_f =
110
+ repzo_tags === null || repzo_tags === void 0
111
+ ? void 0
112
+ : repzo_tags.data) === null || _f === void 0
113
+ ? void 0
114
+ : _f.length
115
+ } Area Tags in Repzo`
116
+ )
117
+ .commit();
118
+ const sap_stores = {};
119
+ sap_inventories_items.forEach((item) => {
120
+ if (!sap_stores[item.STOREID])
121
+ sap_stores[item.STOREID] = { STOREID: item.STOREID, items: [] };
122
+ sap_stores[item.STOREID].items.push(item);
123
+ });
124
+ const sap_inventories = Object.values(sap_stores);
125
+ for (let i = 0; i < sap_inventories.length; i++) {
126
+ try {
127
+ const sap_inventory = sap_inventories[i];
128
+ const repzo_warehouse =
129
+ (_g =
130
+ repzo_warehouses === null || repzo_warehouses === void 0
131
+ ? void 0
132
+ : repzo_warehouses.data) === null || _g === void 0
133
+ ? void 0
134
+ : _g.find((wh) => wh.code == sap_inventory.STOREID);
135
+ if (!repzo_warehouse) {
136
+ throw `Warehouse with code: ${sap_inventory.STOREID} was not found in Repzo`;
137
+ }
138
+ // Get Repzo Inventory
139
+ const repzo_inventory = await repzo.inventory.find({
140
+ warehouse_id: repzo_warehouse._id,
141
+ per_page: 50000,
142
+ });
143
+ const body = {
144
+ time: Date.now(),
145
+ sync_id: uuid(),
146
+ to: repzo_warehouse._id,
147
+ //@ts-ignore
148
+ variants: sap_inventory.items
149
+ .map((sap_item) => {
150
+ var _a, _b, _c, _d;
151
+ try {
152
+ const variant =
153
+ (_a =
154
+ repzo_variants === null || repzo_variants === void 0
155
+ ? void 0
156
+ : repzo_variants.data) === null || _a === void 0
157
+ ? void 0
158
+ : _a.find((variant) => {
159
+ var _a;
160
+ return (
161
+ ((_a = variant.integration_meta) === null ||
162
+ _a === void 0
163
+ ? void 0
164
+ : _a.ITEMCODE) == sap_item.ITEMID
165
+ );
166
+ });
167
+ if (!variant) {
168
+ console.log(
169
+ `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`
170
+ );
171
+ throw `Variant with ITEMCODE: ${sap_item.ITEMID} was not found`;
172
+ }
173
+ const measureUnit =
174
+ (_b =
175
+ repzo_measureunits === null || repzo_measureunits === void 0
176
+ ? void 0
177
+ : repzo_measureunits.data) === null || _b === void 0
178
+ ? void 0
179
+ : _b.find((measure_unit) => {
180
+ var _a, _b;
181
+ return (
182
+ measure_unit._id.toString() ==
183
+ ((_b =
184
+ (_a = variant.product) === null || _a === void 0
185
+ ? void 0
186
+ : _a.sv_measureUnit) === null || _b === void 0
187
+ ? void 0
188
+ : _b.toString())
189
+ );
190
+ });
191
+ if (!measureUnit) {
192
+ console.log(
193
+ `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`
194
+ );
195
+ throw `MeasureUnit with UNITNAME: ${sap_item.UNITNAME} & ALTUOMID: ${sap_item.UNITID} was not found`;
196
+ }
197
+ const qty = measureUnit.factor * sap_item.QTY;
198
+ const match_item_in_repzo_inventory =
199
+ (_c =
200
+ repzo_inventory === null || repzo_inventory === void 0
201
+ ? void 0
202
+ : repzo_inventory.data) === null || _c === void 0
203
+ ? void 0
204
+ : _c.find(
205
+ (repzo_item) =>
206
+ repzo_item.variant_id.toString() ==
207
+ variant._id.toString()
208
+ );
209
+ if (match_item_in_repzo_inventory) {
210
+ //@ts-ignore
211
+ match_item_in_repzo_inventory.has_match_in_SAP = true;
212
+ }
213
+ const diff_qty = match_item_in_repzo_inventory
214
+ ? qty - match_item_in_repzo_inventory.qty
215
+ : qty;
216
+ return { variant: variant._id, qty: diff_qty };
217
+ } catch (e) {
218
+ console.log(e);
219
+ failed_docs_report.push({
220
+ method: "fetchingData",
221
+ doc_id: sap_item.UNITNAME,
222
+ doc: {
223
+ ...sap_item,
224
+ STOREID:
225
+ (_d = sap_inventories[i]) === null || _d === void 0
226
+ ? void 0
227
+ : _d.STOREID,
228
+ },
229
+ error_message: set_error(e),
230
+ });
231
+ result.items_failed++;
232
+ }
233
+ })
234
+ .concat(
235
+ ...((_h =
236
+ repzo_inventory === null || repzo_inventory === void 0
237
+ ? void 0
238
+ : repzo_inventory.data) === null || _h === void 0
239
+ ? void 0
240
+ : _h
241
+ .filter((item) => !item.has_match_in_SAP)
242
+ .map((item) => {
243
+ return { variant: item.variant_id, qty: -1 * item.qty };
244
+ }))
245
+ )
246
+ .filter((item) => item && item.qty),
247
+ };
248
+ // console.log(body);
249
+ if (!body.variants.length) continue;
250
+ const res = await repzo.adjustInventory.create(body);
251
+ result.created++;
252
+ } catch (e) {
253
+ // console.log(e);
254
+ failed_docs_report.push({
255
+ method: "fetchingData",
256
+ doc_id:
257
+ (_j = sap_inventories[i]) === null || _j === void 0
258
+ ? void 0
259
+ : _j.STOREID,
260
+ doc: {
261
+ STOREID:
262
+ (_k = sap_inventories[i]) === null || _k === void 0
263
+ ? void 0
264
+ : _k.STOREID,
265
+ },
266
+ error_message: set_error(e),
267
+ });
268
+ result.failed++;
269
+ }
270
+ }
271
+ // console.log(result);
272
+ await commandLog
273
+ .setStatus(
274
+ "success",
275
+ failed_docs_report.length ? failed_docs_report : null
276
+ )
277
+ .setBody(result)
278
+ .commit();
279
+ return result;
280
+ } catch (e) {
281
+ //@ts-ignore
282
+ console.error(
283
+ ((_l = e === null || e === void 0 ? void 0 : e.response) === null ||
284
+ _l === void 0
285
+ ? void 0
286
+ : _l.data) || e
287
+ );
288
+ await commandLog.setStatus("fail", e).commit();
289
+ throw e;
290
+ }
291
+ };
292
+ const get_sap_inventories = async (serviceEndPoint, query) => {
293
+ try {
294
+ const sap_inventories = await _create(
295
+ serviceEndPoint,
296
+ "/StoresBalance",
297
+ {}
298
+ );
299
+ return sap_inventories.StoresBalance;
300
+ } catch (e) {
301
+ throw e;
302
+ }
303
+ };
@@ -0,0 +1,7 @@
1
+ import { CommandEvent, Result } from "../types";
2
+ export declare const sync_bank: (commandEvent: CommandEvent) => Promise<
3
+ Result & {
4
+ repzo_bank_list_total: number;
5
+ repzo_bank_list_updated: boolean;
6
+ }
7
+ >;
@@ -0,0 +1,301 @@
1
+ import Repzo from "repzo";
2
+ import DataSet from "data-set-query";
3
+ import { _create, update_bench_time, set_error } from "../util.js";
4
+ export const sync_bank = async (commandEvent) => {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
6
+ const repzo = new Repzo(
7
+ (_a = commandEvent.app.formData) === null || _a === void 0
8
+ ? void 0
9
+ : _a.repzoApiKey,
10
+ {
11
+ env: commandEvent.env,
12
+ }
13
+ );
14
+ const commandLog = new Repzo.CommandLog(
15
+ repzo,
16
+ commandEvent.app,
17
+ commandEvent.command
18
+ );
19
+ try {
20
+ console.log("sync_bank");
21
+ const new_bench_time = new Date().toISOString();
22
+ const bench_time_key = "bench_time_bank";
23
+ await commandLog.load(commandEvent.sync_id);
24
+ await commandLog.addDetail("Repzo SAP: Started Syncing Banks").commit();
25
+ const nameSpace = commandEvent.nameSpace.join("_");
26
+ const result = {
27
+ sap_total: 0,
28
+ repzo_total: 0,
29
+ created: 0,
30
+ updated: 0,
31
+ failed: 0,
32
+ repzo_bank_list_total: 0,
33
+ repzo_bank_list_updated: false,
34
+ };
35
+ const failed_docs_report = [];
36
+ const country_translator = {
37
+ JO: "Jordan",
38
+ };
39
+ // Bank **************************************************
40
+ const sap_banks = await get_sap_banks(
41
+ commandEvent.app.formData.sapHostUrl,
42
+ {}
43
+ );
44
+ result.sap_total =
45
+ sap_banks === null || sap_banks === void 0 ? void 0 : sap_banks.length;
46
+ await commandLog.addDetail(`${result.sap_total} Banks in SAP`).commit();
47
+ const db = new DataSet([], { autoIndex: false });
48
+ db.createIndex({
49
+ BANKNAME: true,
50
+ BANKCODE: true,
51
+ COUNTRY: true,
52
+ });
53
+ db.load(sap_banks);
54
+ const sap_bank_query =
55
+ sap_banks === null || sap_banks === void 0
56
+ ? void 0
57
+ : sap_banks.map((bank) => `${nameSpace}_${bank.BANKCODE}`);
58
+ const repzo_banks = await repzo.bank.find({
59
+ "integration_meta.company_namespace": nameSpace,
60
+ per_page: 50000,
61
+ });
62
+ result.repzo_total =
63
+ (_b =
64
+ repzo_banks === null || repzo_banks === void 0
65
+ ? void 0
66
+ : repzo_banks.data) === null || _b === void 0
67
+ ? void 0
68
+ : _b.length;
69
+ await commandLog
70
+ .addDetail(
71
+ `${
72
+ (_c =
73
+ repzo_banks === null || repzo_banks === void 0
74
+ ? void 0
75
+ : repzo_banks.data) === null || _c === void 0
76
+ ? void 0
77
+ : _c.length
78
+ } Banks in Repzo`
79
+ )
80
+ .commit();
81
+ for (
82
+ let i = 0;
83
+ i <
84
+ (sap_banks === null || sap_banks === void 0 ? void 0 : sap_banks.length);
85
+ i++
86
+ ) {
87
+ const sap_bank = sap_banks[i];
88
+ const repzo_bank = repzo_banks.data.find((r_bank) => {
89
+ var _a;
90
+ return (
91
+ ((_a = r_bank.integration_meta) === null || _a === void 0
92
+ ? void 0
93
+ : _a.id) == `${nameSpace}_${sap_bank.BANKCODE}`
94
+ );
95
+ });
96
+ const country = country_translator[sap_bank.COUNTRY];
97
+ if (!country && sap_bank.COUNTRY) {
98
+ throw `COUNTRY of COUNTRY Code: ${sap_bank.COUNTRY} was not found on the translator`;
99
+ }
100
+ const body = {
101
+ name: sap_bank.BANKNAME,
102
+ country: [country],
103
+ integration_meta: {
104
+ id: `${nameSpace}_${sap_bank.BANKCODE}`,
105
+ BANKCODE: sap_bank.BANKCODE,
106
+ COUNTRY: sap_bank.COUNTRY,
107
+ company_namespace: nameSpace,
108
+ },
109
+ };
110
+ if (!repzo_bank) {
111
+ // Create
112
+ try {
113
+ const created_bank = await repzo.bank.create(body);
114
+ result.created++;
115
+ } catch (e) {
116
+ console.log(
117
+ "Create Bank Failed >> ",
118
+ e === null || e === void 0 ? void 0 : e.response,
119
+ body
120
+ );
121
+ failed_docs_report.push({
122
+ method: "create",
123
+ doc: body,
124
+ error_message: set_error(e),
125
+ });
126
+ result.failed++;
127
+ }
128
+ } else {
129
+ if (
130
+ (repzo_bank === null || repzo_bank === void 0
131
+ ? void 0
132
+ : repzo_bank.name) ==
133
+ (body === null || body === void 0 ? void 0 : body.name) &&
134
+ ((_d =
135
+ repzo_bank === null || repzo_bank === void 0
136
+ ? void 0
137
+ : repzo_bank.integration_meta) === null || _d === void 0
138
+ ? void 0
139
+ : _d.COUNTRY) ==
140
+ ((_e =
141
+ body === null || body === void 0
142
+ ? void 0
143
+ : body.integration_meta) === null || _e === void 0
144
+ ? void 0
145
+ : _e.COUNTRY) &&
146
+ ((_f =
147
+ repzo_bank === null || repzo_bank === void 0
148
+ ? void 0
149
+ : repzo_bank.integration_meta) === null || _f === void 0
150
+ ? void 0
151
+ : _f.BANKCODE) ==
152
+ ((_g =
153
+ body === null || body === void 0
154
+ ? void 0
155
+ : body.integration_meta) === null || _g === void 0
156
+ ? void 0
157
+ : _g.BANKCODE)
158
+ )
159
+ continue;
160
+ // Update
161
+ try {
162
+ const updated_bank = await repzo.bank.update(repzo_bank._id, body);
163
+ result.updated++;
164
+ } catch (e) {
165
+ console.log(
166
+ "Update Bank Failed >> ",
167
+ (_h = e === null || e === void 0 ? void 0 : e.response) === null ||
168
+ _h === void 0
169
+ ? void 0
170
+ : _h.data,
171
+ body
172
+ );
173
+ failed_docs_report.push({
174
+ method: "update",
175
+ doc_id:
176
+ repzo_bank === null || repzo_bank === void 0
177
+ ? void 0
178
+ : repzo_bank._id,
179
+ doc: body,
180
+ error_message: set_error(e),
181
+ });
182
+ result.failed++;
183
+ }
184
+ }
185
+ }
186
+ // console.log(result);
187
+ // *******************************************************
188
+ // Bank List *********************************************
189
+ const all_nameSpace_banks = await repzo.bank.find({
190
+ "integration_meta.company_namespace": nameSpace,
191
+ per_page: 50000,
192
+ });
193
+ const repzo_bankLists = await repzo.bank_list.find({
194
+ "integration_meta.id": nameSpace,
195
+ per_page: 50000,
196
+ });
197
+ result.repzo_bank_list_total =
198
+ (_j =
199
+ repzo_banks === null || repzo_banks === void 0
200
+ ? void 0
201
+ : repzo_banks.data) === null || _j === void 0
202
+ ? void 0
203
+ : _j.length;
204
+ if (
205
+ ((_k = repzo_bankLists.data) === null || _k === void 0
206
+ ? void 0
207
+ : _k.length) > 1
208
+ ) {
209
+ throw `Each nameSpace should have One Bank List but nameSpace: ${nameSpace} more than one Bank List`;
210
+ }
211
+ const repzo_bank_list =
212
+ (_l =
213
+ repzo_bankLists === null || repzo_bankLists === void 0
214
+ ? void 0
215
+ : repzo_bankLists.data) === null || _l === void 0
216
+ ? void 0
217
+ : _l[0];
218
+ if (repzo_bank_list) {
219
+ const ids = {};
220
+ (_m =
221
+ repzo_bank_list === null || repzo_bank_list === void 0
222
+ ? void 0
223
+ : repzo_bank_list.banks) === null || _m === void 0
224
+ ? void 0
225
+ : _m.forEach((bank) => {
226
+ var _a;
227
+ ids[
228
+ (_a = bank === null || bank === void 0 ? void 0 : bank.bank) ===
229
+ null || _a === void 0
230
+ ? void 0
231
+ : _a.toString()
232
+ ] = true;
233
+ });
234
+ (_o =
235
+ all_nameSpace_banks === null || all_nameSpace_banks === void 0
236
+ ? void 0
237
+ : all_nameSpace_banks.data) === null || _o === void 0
238
+ ? void 0
239
+ : _o.forEach((bank) => {
240
+ var _a;
241
+ ids[
242
+ (_a = bank === null || bank === void 0 ? void 0 : bank._id) ===
243
+ null || _a === void 0
244
+ ? void 0
245
+ : _a.toString()
246
+ ] = true;
247
+ });
248
+ const new_banks = Object.keys(ids).map((bank_id) => {
249
+ return { bank: bank_id };
250
+ });
251
+ const repzo_bankList_updated = await repzo.bank_list.update(
252
+ (_p =
253
+ repzo_bank_list === null || repzo_bank_list === void 0
254
+ ? void 0
255
+ : repzo_bank_list._id) === null || _p === void 0
256
+ ? void 0
257
+ : _p.toString(),
258
+ {
259
+ ...repzo_bank_list,
260
+ banks: new_banks,
261
+ }
262
+ );
263
+ result.repzo_bank_list_updated = true;
264
+ } else {
265
+ throw `Please Check with IT teams to create BankList for Your nameSpace`;
266
+ }
267
+ // *******************************************************
268
+ await update_bench_time(
269
+ repzo,
270
+ commandEvent.app._id,
271
+ bench_time_key,
272
+ new_bench_time
273
+ );
274
+ await commandLog
275
+ .setStatus(
276
+ "success",
277
+ failed_docs_report.length ? failed_docs_report : null
278
+ )
279
+ .setBody(result)
280
+ .commit();
281
+ return result;
282
+ } catch (e) {
283
+ //@ts-ignore
284
+ console.error(
285
+ ((_q = e === null || e === void 0 ? void 0 : e.response) === null ||
286
+ _q === void 0
287
+ ? void 0
288
+ : _q.data) || e
289
+ );
290
+ await commandLog.setStatus("fail", e).commit();
291
+ throw e;
292
+ }
293
+ };
294
+ const get_sap_banks = async (serviceEndPoint, query) => {
295
+ try {
296
+ const sap_banks = await _create(serviceEndPoint, "/Banks", {});
297
+ return sap_banks.Banks;
298
+ } catch (e) {
299
+ throw e;
300
+ }
301
+ };
@@ -0,0 +1,2 @@
1
+ import { CommandEvent } from "../types";
2
+ export declare const basic: (commandEvent: CommandEvent) => Promise<void>;