repzo-sap-absjo 1.0.20 → 1.0.22
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.
- package/changelog.md +1 -0
- package/lib/actions/create_invoice.d.ts +19 -13
- package/lib/actions/create_invoice.js +359 -210
- package/lib/actions/create_payment.d.ts +4 -1
- package/lib/actions/create_payment.js +195 -107
- package/lib/actions/create_proforma.d.ts +4 -1
- package/lib/actions/create_proforma.js +288 -147
- package/lib/actions/create_return_invoice.d.ts +4 -1
- package/lib/actions/create_return_invoice.js +312 -158
- package/lib/actions/create_transfer.d.ts +4 -1
- package/lib/actions/create_transfer.js +223 -126
- package/lib/actions/index.js +23 -15
- package/lib/commands/adjust_inventory.d.ts +4 -2
- package/lib/commands/adjust_inventory.js +290 -160
- package/lib/commands/bank.d.ts +4 -2
- package/lib/commands/bank.js +279 -157
- package/lib/commands/basic.js +68 -48
- package/lib/commands/brand.d.ts +3 -1
- package/lib/commands/brand.js +174 -100
- package/lib/commands/category.d.ts +3 -1
- package/lib/commands/category.js +178 -104
- package/lib/commands/channel.d.ts +3 -1
- package/lib/commands/channel.js +198 -117
- package/lib/commands/client.d.ts +34 -32
- package/lib/commands/client.js +404 -244
- package/lib/commands/client_disabled.d.ts +3 -1
- package/lib/commands/client_disabled.js +163 -94
- package/lib/commands/index.d.ts +24 -11
- package/lib/commands/index.js +65 -62
- package/lib/commands/join.js +192 -66
- package/lib/commands/measureunit.d.ts +19 -14
- package/lib/commands/measureunit.js +289 -191
- package/lib/commands/measureunit_family.d.ts +10 -8
- package/lib/commands/measureunit_family.js +250 -138
- package/lib/commands/payment_term.d.ts +3 -1
- package/lib/commands/payment_term.js +202 -123
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +617 -326
- package/lib/commands/price_list_disabled.d.ts +12 -0
- package/lib/commands/price_list_disabled.js +216 -0
- package/lib/commands/product.d.ts +32 -30
- package/lib/commands/product.js +485 -263
- package/lib/commands/product_disabled.d.ts +3 -1
- package/lib/commands/product_disabled.js +160 -94
- package/lib/commands/rep.js +221 -141
- package/lib/commands/tag.js +174 -109
- package/lib/commands/tax.js +177 -112
- package/lib/commands/warehouse.d.ts +3 -1
- package/lib/commands/warehouse.js +207 -119
- package/lib/index.d.ts +30 -12
- package/lib/test/actions/create_invoice.js +193 -188
- package/lib/test/actions/create_payment.js +112 -107
- package/lib/test/actions/create_proforma.js +220 -216
- package/lib/test/actions/create_return_invoice.js +205 -200
- package/lib/test/actions/create_transfer.js +120 -115
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +335 -327
- package/lib/test/commands/brand.js +90 -90
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +355 -353
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +328 -327
- package/lib/test/commands/measureunit.js +90 -90
- package/lib/test/commands/measureunit_family.js +90 -90
- package/lib/test/commands/payment_term.js +90 -90
- package/lib/test/commands/price_list.js +337 -334
- package/lib/test/commands/price_list_disabled.d.ts +1 -0
- package/lib/test/commands/price_list_disabled.js +359 -0
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +346 -344
- package/lib/test/commands/tag.js +90 -90
- package/lib/test/commands/tax.js +90 -90
- package/lib/test/commands/warehouse.js +90 -90
- package/lib/types.d.ts +78 -53
- package/lib/util.d.ts +76 -19
- package/lib/util.js +179 -144
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +7 -18
- package/src/actions/create_proforma.ts +11 -1
- package/src/commands/basic.ts +1 -0
- package/src/commands/index.ts +3 -0
- package/src/commands/price_list.ts +7 -2
- package/src/commands/price_list_disabled.ts +194 -0
- package/src/test/commands/basic.ts +7 -0
- package/src/test/commands/price_list_disabled.ts +362 -0
- package/src/types.ts +1 -0
- package/src/util.ts +18 -1
|
@@ -1,101 +1,167 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
_create,
|
|
4
|
+
update_bench_time,
|
|
5
|
+
date_formatting,
|
|
6
|
+
set_error,
|
|
7
|
+
} from "../util.js";
|
|
3
8
|
export const sync_disabled_product = async (commandEvent) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const new_bench_time = new Date().toISOString();
|
|
12
|
-
const bench_time_key = "bench_time_product_disabled";
|
|
13
|
-
await commandLog.load(commandEvent.sync_id);
|
|
14
|
-
await commandLog
|
|
15
|
-
.addDetail("Repzo SAP: Started Syncing Disabled Products")
|
|
16
|
-
.commit();
|
|
17
|
-
const nameSpace = commandEvent.nameSpace.join("_");
|
|
18
|
-
const result = {
|
|
19
|
-
sap_total: 0,
|
|
20
|
-
repzo_total: 0,
|
|
21
|
-
created: 0,
|
|
22
|
-
updated: 0,
|
|
23
|
-
failed: 0,
|
|
24
|
-
};
|
|
25
|
-
const failed_docs_report = [];
|
|
26
|
-
const sap_products = await get_sap_disabled_products(commandEvent.app.formData.sapHostUrl, { updateAt: commandEvent.app.options_formData[bench_time_key] });
|
|
27
|
-
result.sap_total = sap_products === null || sap_products === void 0 ? void 0 : sap_products.length;
|
|
28
|
-
await commandLog
|
|
29
|
-
.addDetail(`${result.sap_total} Disabled Products in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
|
|
30
|
-
.commit();
|
|
31
|
-
const sap_product_query = sap_products === null || sap_products === void 0 ? void 0 : sap_products.map((product) => `${nameSpace}_${product.ITEMCODE}`);
|
|
32
|
-
const repzo_product_per_page = await repzo.patchAction.create({
|
|
33
|
-
slug: "product",
|
|
34
|
-
readQuery: [
|
|
35
|
-
{ key: "active", value: [true], operator: "eq" },
|
|
36
|
-
{
|
|
37
|
-
key: "integration_meta.id",
|
|
38
|
-
value: sap_product_query,
|
|
39
|
-
operator: "in",
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
}, { per_page: 50000 });
|
|
43
|
-
const repzo_products = repzo_product_per_page.data;
|
|
44
|
-
result.repzo_total = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.length;
|
|
45
|
-
await commandLog
|
|
46
|
-
.addDetail(`${result.repzo_total} Active Products in Repzo should be disabled`)
|
|
47
|
-
.commit();
|
|
48
|
-
for (let i = 0; i < (sap_products === null || sap_products === void 0 ? void 0 : sap_products.length); i++) {
|
|
49
|
-
const sap_product = sap_products[i];
|
|
50
|
-
const repzo_product = repzo_products.find((r_product) => {
|
|
51
|
-
var _a;
|
|
52
|
-
return ((_a = r_product === null || r_product === void 0 ? void 0 : r_product.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
|
|
53
|
-
`${nameSpace}_${sap_product.ITEMCODE}`;
|
|
54
|
-
});
|
|
55
|
-
if (repzo_product) {
|
|
56
|
-
// Update
|
|
57
|
-
try {
|
|
58
|
-
const disabled_product = await repzo.product.remove(repzo_product._id);
|
|
59
|
-
result.updated++;
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
// console.log("Disabled Product Failed >> ", e?.response?.data, {
|
|
63
|
-
// ITEMCODE: sap_product.ITEMCODE,
|
|
64
|
-
// });
|
|
65
|
-
failed_docs_report.push({
|
|
66
|
-
method: "delete",
|
|
67
|
-
doc_id: repzo_product === null || repzo_product === void 0 ? void 0 : repzo_product._id,
|
|
68
|
-
doc: { ITEMCODE: sap_product.ITEMCODE },
|
|
69
|
-
error_message: set_error(e),
|
|
70
|
-
});
|
|
71
|
-
result.failed++;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// console.log(result);
|
|
76
|
-
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
77
|
-
await commandLog
|
|
78
|
-
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
79
|
-
.setBody(result)
|
|
80
|
-
.commit();
|
|
81
|
-
return result;
|
|
9
|
+
var _a, _b;
|
|
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,
|
|
82
16
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
17
|
+
);
|
|
18
|
+
const commandLog = new Repzo.CommandLog(
|
|
19
|
+
repzo,
|
|
20
|
+
commandEvent.app,
|
|
21
|
+
commandEvent.command
|
|
22
|
+
);
|
|
23
|
+
try {
|
|
24
|
+
// console.log("sync_disabled_product");
|
|
25
|
+
const new_bench_time = new Date().toISOString();
|
|
26
|
+
const bench_time_key = "bench_time_product_disabled";
|
|
27
|
+
await commandLog.load(commandEvent.sync_id);
|
|
28
|
+
await commandLog
|
|
29
|
+
.addDetail("Repzo SAP: Started Syncing Disabled Products")
|
|
30
|
+
.commit();
|
|
31
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
32
|
+
const result = {
|
|
33
|
+
sap_total: 0,
|
|
34
|
+
repzo_total: 0,
|
|
35
|
+
created: 0,
|
|
36
|
+
updated: 0,
|
|
37
|
+
failed: 0,
|
|
38
|
+
};
|
|
39
|
+
const failed_docs_report = [];
|
|
40
|
+
const sap_products = await get_sap_disabled_products(
|
|
41
|
+
commandEvent.app.formData.sapHostUrl,
|
|
42
|
+
{ updateAt: commandEvent.app.options_formData[bench_time_key] }
|
|
43
|
+
);
|
|
44
|
+
result.sap_total =
|
|
45
|
+
sap_products === null || sap_products === void 0
|
|
46
|
+
? void 0
|
|
47
|
+
: sap_products.length;
|
|
48
|
+
await commandLog
|
|
49
|
+
.addDetail(
|
|
50
|
+
`${result.sap_total} Disabled Products in SAP changed since ${
|
|
51
|
+
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
52
|
+
}`
|
|
53
|
+
)
|
|
54
|
+
.commit();
|
|
55
|
+
const sap_product_query =
|
|
56
|
+
sap_products === null || sap_products === void 0
|
|
57
|
+
? void 0
|
|
58
|
+
: sap_products.map((product) => `${nameSpace}_${product.ITEMCODE}`);
|
|
59
|
+
const repzo_product_per_page = await repzo.patchAction.create(
|
|
60
|
+
{
|
|
61
|
+
slug: "product",
|
|
62
|
+
readQuery: [
|
|
63
|
+
{ key: "active", value: [true], operator: "eq" },
|
|
64
|
+
{
|
|
65
|
+
key: "integration_meta.id",
|
|
66
|
+
value: sap_product_query,
|
|
67
|
+
operator: "in",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{ per_page: 50000 }
|
|
72
|
+
);
|
|
73
|
+
const repzo_products = repzo_product_per_page.data;
|
|
74
|
+
result.repzo_total =
|
|
75
|
+
repzo_products === null || repzo_products === void 0
|
|
76
|
+
? void 0
|
|
77
|
+
: repzo_products.length;
|
|
78
|
+
await commandLog
|
|
79
|
+
.addDetail(
|
|
80
|
+
`${result.repzo_total} Active Products in Repzo should be disabled`
|
|
81
|
+
)
|
|
82
|
+
.commit();
|
|
83
|
+
for (
|
|
84
|
+
let i = 0;
|
|
85
|
+
i <
|
|
86
|
+
(sap_products === null || sap_products === void 0
|
|
87
|
+
? void 0
|
|
88
|
+
: sap_products.length);
|
|
89
|
+
i++
|
|
90
|
+
) {
|
|
91
|
+
const sap_product = sap_products[i];
|
|
92
|
+
const repzo_product = repzo_products.find((r_product) => {
|
|
93
|
+
var _a;
|
|
94
|
+
return (
|
|
95
|
+
((_a =
|
|
96
|
+
r_product === null || r_product === void 0
|
|
97
|
+
? void 0
|
|
98
|
+
: r_product.integration_meta) === null || _a === void 0
|
|
99
|
+
? void 0
|
|
100
|
+
: _a.id) == `${nameSpace}_${sap_product.ITEMCODE}`
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
if (repzo_product) {
|
|
104
|
+
// Update
|
|
105
|
+
try {
|
|
106
|
+
const disabled_product = await repzo.product.remove(
|
|
107
|
+
repzo_product._id
|
|
108
|
+
);
|
|
109
|
+
result.updated++;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
// console.log("Disabled Product Failed >> ", e?.response?.data, {
|
|
112
|
+
// ITEMCODE: sap_product.ITEMCODE,
|
|
113
|
+
// });
|
|
114
|
+
failed_docs_report.push({
|
|
115
|
+
method: "delete",
|
|
116
|
+
doc_id:
|
|
117
|
+
repzo_product === null || repzo_product === void 0
|
|
118
|
+
? void 0
|
|
119
|
+
: repzo_product._id,
|
|
120
|
+
doc: { ITEMCODE: sap_product.ITEMCODE },
|
|
121
|
+
error_message: set_error(e),
|
|
122
|
+
});
|
|
123
|
+
result.failed++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
88
126
|
}
|
|
127
|
+
// console.log(result);
|
|
128
|
+
await update_bench_time(
|
|
129
|
+
repzo,
|
|
130
|
+
commandEvent.app._id,
|
|
131
|
+
bench_time_key,
|
|
132
|
+
new_bench_time
|
|
133
|
+
);
|
|
134
|
+
await commandLog
|
|
135
|
+
.setStatus(
|
|
136
|
+
"success",
|
|
137
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
138
|
+
)
|
|
139
|
+
.setBody(result)
|
|
140
|
+
.commit();
|
|
141
|
+
return result;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
//@ts-ignore
|
|
144
|
+
console.error(
|
|
145
|
+
((_b = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
146
|
+
_b === void 0
|
|
147
|
+
? void 0
|
|
148
|
+
: _b.data) || e
|
|
149
|
+
);
|
|
150
|
+
await commandLog.setStatus("fail", e).commit();
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
89
153
|
};
|
|
90
154
|
const get_sap_disabled_products = async (serviceEndPoint, query) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
155
|
+
try {
|
|
156
|
+
const sap_products = await _create(serviceEndPoint, "/Items", {
|
|
157
|
+
Active: "N",
|
|
158
|
+
UpdateAt: date_formatting(
|
|
159
|
+
query === null || query === void 0 ? void 0 : query.updateAt,
|
|
160
|
+
"YYYYMMDD:HHmmss"
|
|
161
|
+
),
|
|
162
|
+
});
|
|
163
|
+
return sap_products.Items;
|
|
164
|
+
} catch (e) {
|
|
165
|
+
throw e;
|
|
166
|
+
}
|
|
101
167
|
};
|
package/lib/commands/rep.js
CHANGED
|
@@ -1,151 +1,231 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
2
|
import DataSet from "data-set-query";
|
|
3
|
-
import { _create, update_bench_time, set_error
|
|
3
|
+
import { _create, update_bench_time, set_error } from "../util.js";
|
|
4
4
|
export const sync_rep = async (commandEvent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
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_rep");
|
|
21
|
+
const new_bench_time = new Date().toISOString();
|
|
22
|
+
const bench_time_key = "bench_time_rep";
|
|
23
|
+
await commandLog.load(commandEvent.sync_id);
|
|
24
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Reps").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
|
+
};
|
|
33
|
+
const failed_docs_report = [];
|
|
34
|
+
const sap_reps = await get_sap_reps(
|
|
35
|
+
commandEvent.app.formData.sapHostUrl,
|
|
36
|
+
{}
|
|
37
|
+
);
|
|
38
|
+
result.sap_total =
|
|
39
|
+
(_b =
|
|
40
|
+
sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
|
|
41
|
+
null || _b === void 0
|
|
42
|
+
? void 0
|
|
43
|
+
: _b.length;
|
|
44
|
+
await commandLog.addDetail(`${result.sap_total} reps in SAP`).commit();
|
|
45
|
+
// hard code ************************************
|
|
46
|
+
// sap_reps?.Users?.forEach((sap_rep) => {
|
|
47
|
+
// if (
|
|
48
|
+
// sap_rep.USERDESC.startsWith("WS ") ||
|
|
49
|
+
// sap_rep.USERDESC.startsWith("RET ")
|
|
50
|
+
// ) {
|
|
51
|
+
// sap_rep.USERWHSCODE = "1";
|
|
52
|
+
// }
|
|
53
|
+
// if (sap_rep.USERDESC.startsWith("MT ")) {
|
|
54
|
+
// sap_rep.USERWHSCODE = "K.A";
|
|
55
|
+
// }
|
|
56
|
+
// });
|
|
57
|
+
// **********************************************
|
|
58
|
+
const db = new DataSet([], { autoIndex: false });
|
|
59
|
+
db.createIndex({
|
|
60
|
+
USERID: true,
|
|
61
|
+
USERDESC: true,
|
|
62
|
+
DEPARTMENTCODE: true,
|
|
63
|
+
USERCASHACCOUNT: true,
|
|
64
|
+
USERCHECKACCTCODE: true,
|
|
65
|
+
USERWHSCODE: true,
|
|
8
66
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
db.load(sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users);
|
|
68
|
+
const repzo_reps = await repzo.rep.find({ per_page: 50000 });
|
|
69
|
+
result.repzo_total =
|
|
70
|
+
(_c =
|
|
71
|
+
repzo_reps === null || repzo_reps === void 0
|
|
72
|
+
? void 0
|
|
73
|
+
: repzo_reps.data) === null || _c === void 0
|
|
74
|
+
? void 0
|
|
75
|
+
: _c.length;
|
|
76
|
+
await commandLog
|
|
77
|
+
.addDetail(
|
|
78
|
+
`${
|
|
79
|
+
(_d =
|
|
80
|
+
repzo_reps === null || repzo_reps === void 0
|
|
81
|
+
? void 0
|
|
82
|
+
: repzo_reps.data) === null || _d === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _d.length
|
|
85
|
+
} reps in Repzo`
|
|
86
|
+
)
|
|
87
|
+
.commit();
|
|
88
|
+
for (
|
|
89
|
+
let i = 0;
|
|
90
|
+
i <
|
|
91
|
+
((_e =
|
|
92
|
+
sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
|
|
93
|
+
null || _e === void 0
|
|
94
|
+
? void 0
|
|
95
|
+
: _e.length);
|
|
96
|
+
i++
|
|
97
|
+
) {
|
|
98
|
+
const sap_rep = sap_reps.Users[i];
|
|
99
|
+
const repzo_rep = repzo_reps.data.find((r_rep) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return (
|
|
102
|
+
((_a = r_rep.integration_meta) === null || _a === void 0
|
|
103
|
+
? void 0
|
|
104
|
+
: _a.id) == `${nameSpace}_${sap_rep.USERID}`
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
let warehouse;
|
|
108
|
+
if (sap_rep.USERWHSCODE && sap_rep.USERWHSCODE != "") {
|
|
109
|
+
const warehouse_res = await repzo.warehouse.find({
|
|
110
|
+
code: sap_rep.USERWHSCODE,
|
|
49
111
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
method: "create",
|
|
92
|
-
doc: body,
|
|
93
|
-
error_message: set_error(e),
|
|
94
|
-
});
|
|
95
|
-
result.failed++;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const found_identical_docs = db.search({
|
|
100
|
-
USERID: repzo_rep.integration_id,
|
|
101
|
-
USERDESC: repzo_rep.name,
|
|
102
|
-
DEPARTMENTCODE: (_h = repzo_rep.integration_meta) === null || _h === void 0 ? void 0 : _h.DEPARTMENTCODE,
|
|
103
|
-
USERCASHACCOUNT: (_j = repzo_rep.integration_meta) === null || _j === void 0 ? void 0 : _j.USERCASHACCOUNT,
|
|
104
|
-
USERCHECKACCTCODE: (_k = repzo_rep.integration_meta) === null || _k === void 0 ? void 0 : _k.USERCHECKACCTCODE,
|
|
105
|
-
USERWHSCODE: (_l = repzo_rep.integration_meta) === null || _l === void 0 ? void 0 : _l.USERWHSCODE,
|
|
106
|
-
});
|
|
107
|
-
if (found_identical_docs.length)
|
|
108
|
-
continue;
|
|
109
|
-
// Update
|
|
110
|
-
try {
|
|
111
|
-
// Delete Rep.Password
|
|
112
|
-
delete body.password;
|
|
113
|
-
const updated_rep = await repzo.rep.update(repzo_rep._id, body);
|
|
114
|
-
result.updated++;
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
// console.log("Update Rep Failed >> ", e?.response?.data, body);
|
|
118
|
-
failed_docs_report.push({
|
|
119
|
-
method: "update",
|
|
120
|
-
doc_id: repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep._id,
|
|
121
|
-
doc: body,
|
|
122
|
-
error_message: set_error(e),
|
|
123
|
-
});
|
|
124
|
-
result.failed++;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
112
|
+
if (
|
|
113
|
+
(_f =
|
|
114
|
+
warehouse_res === null || warehouse_res === void 0
|
|
115
|
+
? void 0
|
|
116
|
+
: warehouse_res.data) === null || _f === void 0
|
|
117
|
+
? void 0
|
|
118
|
+
: _f.length
|
|
119
|
+
)
|
|
120
|
+
warehouse = warehouse_res.data[0]._id;
|
|
121
|
+
}
|
|
122
|
+
const body = {
|
|
123
|
+
name: sap_rep.USERDESC,
|
|
124
|
+
password: Math.round(Math.random() * (9999 - 1000) + 1000).toString(),
|
|
125
|
+
username: nameSpace + sap_rep.USERID,
|
|
126
|
+
integration_id:
|
|
127
|
+
(_g = sap_rep.USERID) === null || _g === void 0
|
|
128
|
+
? void 0
|
|
129
|
+
: _g.toString(),
|
|
130
|
+
integration_meta: {
|
|
131
|
+
DEPARTMENTCODE: sap_rep.DEPARTMENTCODE,
|
|
132
|
+
USERCASHACCOUNT: sap_rep.USERCASHACCOUNT,
|
|
133
|
+
USERCHECKACCTCODE: sap_rep.USERCHECKACCTCODE,
|
|
134
|
+
USERWHSCODE: sap_rep.USERWHSCODE,
|
|
135
|
+
id: `${nameSpace}_${sap_rep.USERID}`,
|
|
136
|
+
},
|
|
137
|
+
assigned_warehouse: warehouse,
|
|
138
|
+
company_namespace: [nameSpace],
|
|
139
|
+
};
|
|
140
|
+
if (!repzo_rep) {
|
|
141
|
+
// Create
|
|
142
|
+
try {
|
|
143
|
+
const created_rep = await repzo.rep.create(body);
|
|
144
|
+
result.created++;
|
|
145
|
+
} catch (e) {
|
|
146
|
+
// console.log("Create Rep Failed >> ", e?.response, body);
|
|
147
|
+
failed_docs_report.push({
|
|
148
|
+
method: "create",
|
|
149
|
+
doc: body,
|
|
150
|
+
error_message: set_error(e),
|
|
151
|
+
});
|
|
152
|
+
result.failed++;
|
|
127
153
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
} else {
|
|
155
|
+
const found_identical_docs = db.search({
|
|
156
|
+
USERID: repzo_rep.integration_id,
|
|
157
|
+
USERDESC: repzo_rep.name,
|
|
158
|
+
DEPARTMENTCODE:
|
|
159
|
+
(_h = repzo_rep.integration_meta) === null || _h === void 0
|
|
160
|
+
? void 0
|
|
161
|
+
: _h.DEPARTMENTCODE,
|
|
162
|
+
USERCASHACCOUNT:
|
|
163
|
+
(_j = repzo_rep.integration_meta) === null || _j === void 0
|
|
164
|
+
? void 0
|
|
165
|
+
: _j.USERCASHACCOUNT,
|
|
166
|
+
USERCHECKACCTCODE:
|
|
167
|
+
(_k = repzo_rep.integration_meta) === null || _k === void 0
|
|
168
|
+
? void 0
|
|
169
|
+
: _k.USERCHECKACCTCODE,
|
|
170
|
+
USERWHSCODE:
|
|
171
|
+
(_l = repzo_rep.integration_meta) === null || _l === void 0
|
|
172
|
+
? void 0
|
|
173
|
+
: _l.USERWHSCODE,
|
|
174
|
+
});
|
|
175
|
+
if (found_identical_docs.length) continue;
|
|
176
|
+
// Update
|
|
177
|
+
try {
|
|
178
|
+
// Delete Rep.Password
|
|
179
|
+
delete body.password;
|
|
180
|
+
const updated_rep = await repzo.rep.update(repzo_rep._id, body);
|
|
181
|
+
result.updated++;
|
|
182
|
+
} catch (e) {
|
|
183
|
+
// console.log("Update Rep Failed >> ", e?.response?.data, body);
|
|
184
|
+
failed_docs_report.push({
|
|
185
|
+
method: "update",
|
|
186
|
+
doc_id:
|
|
187
|
+
repzo_rep === null || repzo_rep === void 0
|
|
188
|
+
? void 0
|
|
189
|
+
: repzo_rep._id,
|
|
190
|
+
doc: body,
|
|
191
|
+
error_message: set_error(e),
|
|
192
|
+
});
|
|
193
|
+
result.failed++;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
141
196
|
}
|
|
197
|
+
// console.log(result);
|
|
198
|
+
await update_bench_time(
|
|
199
|
+
repzo,
|
|
200
|
+
commandEvent.app._id,
|
|
201
|
+
bench_time_key,
|
|
202
|
+
new_bench_time
|
|
203
|
+
);
|
|
204
|
+
await commandLog
|
|
205
|
+
.setStatus(
|
|
206
|
+
"success",
|
|
207
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
208
|
+
)
|
|
209
|
+
.setBody(result)
|
|
210
|
+
.commit();
|
|
211
|
+
return result;
|
|
212
|
+
} catch (e) {
|
|
213
|
+
//@ts-ignore
|
|
214
|
+
console.error(
|
|
215
|
+
((_m = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
216
|
+
_m === void 0
|
|
217
|
+
? void 0
|
|
218
|
+
: _m.data) || e
|
|
219
|
+
);
|
|
220
|
+
await commandLog.setStatus("fail", e).commit();
|
|
221
|
+
throw e;
|
|
222
|
+
}
|
|
142
223
|
};
|
|
143
224
|
const get_sap_reps = async (serviceEndPoint, query) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
225
|
+
try {
|
|
226
|
+
const sap_reps = await _create(serviceEndPoint, "/Users", {});
|
|
227
|
+
return sap_reps;
|
|
228
|
+
} catch (e) {
|
|
229
|
+
throw e;
|
|
230
|
+
}
|
|
151
231
|
};
|