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.
- package/README.md +3 -0
- package/changelog.md +17 -0
- package/lib/actions/create_invoice.d.ts +26 -0
- package/lib/actions/create_invoice.js +311 -0
- package/lib/actions/create_payment.d.ts +5 -0
- package/lib/actions/create_payment.js +177 -0
- package/lib/actions/create_proforma.d.ts +5 -0
- package/lib/actions/create_proforma.js +241 -0
- package/lib/actions/create_return_invoice.d.ts +5 -0
- package/lib/actions/create_return_invoice.js +268 -0
- package/lib/actions/create_transfer.d.ts +5 -0
- package/lib/actions/create_transfer.js +171 -0
- package/lib/actions/index.d.ts +3 -0
- package/lib/actions/index.js +31 -0
- package/lib/commands/adjust_inventory.d.ts +6 -0
- package/lib/commands/adjust_inventory.js +303 -0
- package/lib/commands/bank.d.ts +7 -0
- package/lib/commands/bank.js +301 -0
- package/lib/commands/basic.d.ts +2 -0
- package/lib/commands/basic.js +73 -0
- package/lib/commands/category.d.ts +4 -0
- package/lib/commands/category.js +193 -0
- package/lib/commands/channel.d.ts +4 -0
- package/lib/commands/channel.js +213 -0
- package/lib/commands/client.d.ts +39 -0
- package/lib/commands/client.js +410 -0
- package/lib/commands/client_disabled.d.ts +4 -0
- package/lib/commands/client_disabled.js +183 -0
- package/lib/commands/index.d.ts +23 -0
- package/lib/commands/index.js +82 -0
- package/lib/commands/join.d.ts +2 -0
- package/lib/commands/join.js +134 -0
- package/lib/commands/measureunit.d.ts +23 -0
- package/lib/commands/measureunit.js +314 -0
- package/lib/commands/measureunit_family.d.ts +12 -0
- package/lib/commands/measureunit_family.js +263 -0
- package/lib/commands/payment_term.d.ts +4 -0
- package/lib/commands/payment_term.js +217 -0
- package/lib/commands/price_list.d.ts +18 -0
- package/lib/commands/price_list.js +608 -0
- package/lib/commands/product.d.ts +39 -0
- package/lib/commands/product.js +454 -0
- package/lib/commands/product_disabled.d.ts +4 -0
- package/lib/commands/product_disabled.js +178 -0
- package/lib/commands/rep.d.ts +2 -0
- package/lib/commands/rep.js +246 -0
- package/lib/commands/tag.d.ts +2 -0
- package/lib/commands/tag.js +195 -0
- package/lib/commands/tax.d.ts +2 -0
- package/lib/commands/tax.js +198 -0
- package/lib/commands/warehouse.d.ts +4 -0
- package/lib/commands/warehouse.js +221 -0
- package/lib/index.d.ts +29 -0
- package/lib/index.js +6 -0
- package/lib/test/actions/create_invoice.d.ts +1 -0
- package/lib/test/actions/create_invoice.js +214 -0
- package/lib/test/actions/create_payment.d.ts +1 -0
- package/lib/test/actions/create_payment.js +131 -0
- package/lib/test/actions/create_proforma.d.ts +1 -0
- package/lib/test/actions/create_proforma.js +242 -0
- package/lib/test/actions/create_return_invoice.d.ts +1 -0
- package/lib/test/actions/create_return_invoice.js +226 -0
- package/lib/test/actions/create_transfer.d.ts +1 -0
- package/lib/test/actions/create_transfer.js +142 -0
- package/lib/test/commands/adjust_inventory.d.ts +1 -0
- package/lib/test/commands/adjust_inventory.js +97 -0
- package/lib/test/commands/bank.d.ts +1 -0
- package/lib/test/commands/bank.js +97 -0
- package/lib/test/commands/basic.d.ts +1 -0
- package/lib/test/commands/basic.js +339 -0
- package/lib/test/commands/category.d.ts +1 -0
- package/lib/test/commands/category.js +97 -0
- package/lib/test/commands/channel.d.ts +1 -0
- package/lib/test/commands/channel.js +97 -0
- package/lib/test/commands/client.d.ts +1 -0
- package/lib/test/commands/client.js +97 -0
- package/lib/test/commands/client_disabled.d.ts +1 -0
- package/lib/test/commands/client_disabled.js +97 -0
- package/lib/test/commands/join.d.ts +1 -0
- package/lib/test/commands/join.js +339 -0
- package/lib/test/commands/measureunit.d.ts +1 -0
- package/lib/test/commands/measureunit.js +97 -0
- package/lib/test/commands/measureunit_family.d.ts +1 -0
- package/lib/test/commands/measureunit_family.js +97 -0
- package/lib/test/commands/payment_term.d.ts +1 -0
- package/lib/test/commands/payment_term.js +97 -0
- package/lib/test/commands/price_list.d.ts +1 -0
- package/lib/test/commands/price_list.js +97 -0
- package/lib/test/commands/product.d.ts +1 -0
- package/lib/test/commands/product.js +97 -0
- package/lib/test/commands/product_disabled.d.ts +1 -0
- package/lib/test/commands/product_disabled.js +97 -0
- package/lib/test/commands/rep.d.ts +1 -0
- package/lib/test/commands/rep.js +97 -0
- package/lib/test/commands/tag.d.ts +1 -0
- package/lib/test/commands/tag.js +97 -0
- package/lib/test/commands/tax.d.ts +1 -0
- package/lib/test/commands/tax.js +97 -0
- package/lib/test/commands/warehouse.d.ts +1 -0
- package/lib/test/commands/warehouse.js +97 -0
- package/lib/types.d.ts +77 -0
- package/lib/types.js +1 -0
- package/lib/util.d.ts +70 -0
- package/lib/util.js +164 -0
- package/package.json +51 -0
- package/src/actions/create_invoice.ts +275 -0
- package/src/actions/create_payment.ts +138 -0
- package/src/actions/create_proforma.ts +187 -0
- package/src/actions/create_return_invoice.ts +217 -0
- package/src/actions/create_transfer.ts +160 -0
- package/src/actions/index.ts +27 -0
- package/src/commands/adjust_inventory.ts +250 -0
- package/src/commands/bank.ts +243 -0
- package/src/commands/basic.ts +64 -0
- package/src/commands/category.ts +176 -0
- package/src/commands/channel.ts +219 -0
- package/src/commands/client.ts +368 -0
- package/src/commands/client_disabled.ts +158 -0
- package/src/commands/index.ts +87 -0
- package/src/commands/join.ts +80 -0
- package/src/commands/measureunit.ts +276 -0
- package/src/commands/measureunit_family.ts +209 -0
- package/src/commands/payment_term.ts +224 -0
- package/src/commands/price_list.ts +434 -0
- package/src/commands/product.ts +359 -0
- package/src/commands/product_disabled.ts +152 -0
- package/src/commands/rep.ts +209 -0
- package/src/commands/tag.ts +173 -0
- package/src/commands/tax.ts +178 -0
- package/src/commands/warehouse.ts +204 -0
- package/src/index.ts +7 -0
- package/src/test/actions/create_invoice.ts +214 -0
- package/src/test/actions/create_payment.ts +131 -0
- package/src/test/actions/create_proforma.ts +242 -0
- package/src/test/actions/create_return_invoice.ts +226 -0
- package/src/test/actions/create_transfer.ts +142 -0
- package/src/test/commands/adjust_inventory.ts +100 -0
- package/src/test/commands/bank.ts +100 -0
- package/src/test/commands/basic.ts +342 -0
- package/src/test/commands/category.ts +100 -0
- package/src/test/commands/channel.ts +100 -0
- package/src/test/commands/client.ts +100 -0
- package/src/test/commands/client_disabled.ts +100 -0
- package/src/test/commands/join.ts +342 -0
- package/src/test/commands/measureunit.ts +100 -0
- package/src/test/commands/measureunit_family.ts +100 -0
- package/src/test/commands/payment_term.ts +100 -0
- package/src/test/commands/price_list.ts +100 -0
- package/src/test/commands/product.ts +100 -0
- package/src/test/commands/product_disabled.ts +100 -0
- package/src/test/commands/rep.ts +100 -0
- package/src/test/commands/tag.ts +100 -0
- package/src/test/commands/tax.ts +100 -0
- package/src/test/commands/warehouse.ts +100 -0
- package/src/types.ts +76 -0
- package/src/util.ts +205 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,246 @@
|
|
|
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_rep = async (commandEvent) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
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
|
+
(_c =
|
|
47
|
+
sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
|
|
48
|
+
null || _c === void 0
|
|
49
|
+
? void 0
|
|
50
|
+
: _c.forEach((sap_rep) => {
|
|
51
|
+
if (
|
|
52
|
+
sap_rep.USERDESC.startsWith("WS ") ||
|
|
53
|
+
sap_rep.USERDESC.startsWith("RET ")
|
|
54
|
+
) {
|
|
55
|
+
sap_rep.USERWHSCODE = "1";
|
|
56
|
+
}
|
|
57
|
+
if (sap_rep.USERDESC.startsWith("MT ")) {
|
|
58
|
+
sap_rep.USERWHSCODE = "K.A";
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// **********************************************
|
|
62
|
+
const db = new DataSet([], { autoIndex: false });
|
|
63
|
+
db.createIndex({
|
|
64
|
+
USERID: true,
|
|
65
|
+
USERDESC: true,
|
|
66
|
+
DEPARTMENTCODE: true,
|
|
67
|
+
USERCASHACCOUNT: true,
|
|
68
|
+
USERCHECKACCTCODE: true,
|
|
69
|
+
USERWHSCODE: true,
|
|
70
|
+
});
|
|
71
|
+
db.load(sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users);
|
|
72
|
+
const repzo_reps = await repzo.rep.find({ per_page: 50000 });
|
|
73
|
+
result.repzo_total =
|
|
74
|
+
(_d =
|
|
75
|
+
repzo_reps === null || repzo_reps === void 0
|
|
76
|
+
? void 0
|
|
77
|
+
: repzo_reps.data) === null || _d === void 0
|
|
78
|
+
? void 0
|
|
79
|
+
: _d.length;
|
|
80
|
+
await commandLog
|
|
81
|
+
.addDetail(
|
|
82
|
+
`${
|
|
83
|
+
(_e =
|
|
84
|
+
repzo_reps === null || repzo_reps === void 0
|
|
85
|
+
? void 0
|
|
86
|
+
: repzo_reps.data) === null || _e === void 0
|
|
87
|
+
? void 0
|
|
88
|
+
: _e.length
|
|
89
|
+
} reps in Repzo`
|
|
90
|
+
)
|
|
91
|
+
.commit();
|
|
92
|
+
for (
|
|
93
|
+
let i = 0;
|
|
94
|
+
i <
|
|
95
|
+
((_f =
|
|
96
|
+
sap_reps === null || sap_reps === void 0 ? void 0 : sap_reps.Users) ===
|
|
97
|
+
null || _f === void 0
|
|
98
|
+
? void 0
|
|
99
|
+
: _f.length);
|
|
100
|
+
i++
|
|
101
|
+
) {
|
|
102
|
+
const sap_rep = sap_reps.Users[i];
|
|
103
|
+
const repzo_rep = repzo_reps.data.find((r_rep) => {
|
|
104
|
+
var _a;
|
|
105
|
+
return (
|
|
106
|
+
((_a = r_rep.integration_meta) === null || _a === void 0
|
|
107
|
+
? void 0
|
|
108
|
+
: _a.id) == `${nameSpace}_${sap_rep.USERID}`
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
let warehouse;
|
|
112
|
+
if (sap_rep.USERWHSCODE && sap_rep.USERWHSCODE != "") {
|
|
113
|
+
const warehouse_res = await repzo.warehouse.find({
|
|
114
|
+
code: sap_rep.USERWHSCODE,
|
|
115
|
+
});
|
|
116
|
+
if (
|
|
117
|
+
(_g =
|
|
118
|
+
warehouse_res === null || warehouse_res === void 0
|
|
119
|
+
? void 0
|
|
120
|
+
: warehouse_res.data) === null || _g === void 0
|
|
121
|
+
? void 0
|
|
122
|
+
: _g.length
|
|
123
|
+
)
|
|
124
|
+
warehouse = warehouse_res.data[0]._id;
|
|
125
|
+
}
|
|
126
|
+
const body = {
|
|
127
|
+
name: sap_rep.USERDESC,
|
|
128
|
+
password: Math.round(Math.random() * (9999 - 1000) + 1000).toString(),
|
|
129
|
+
username: nameSpace + sap_rep.USERID,
|
|
130
|
+
integration_id:
|
|
131
|
+
(_h = sap_rep.USERID) === null || _h === void 0
|
|
132
|
+
? void 0
|
|
133
|
+
: _h.toString(),
|
|
134
|
+
integration_meta: {
|
|
135
|
+
DEPARTMENTCODE: sap_rep.DEPARTMENTCODE,
|
|
136
|
+
USERCASHACCOUNT: sap_rep.USERCASHACCOUNT,
|
|
137
|
+
USERCHECKACCTCODE: sap_rep.USERCHECKACCTCODE,
|
|
138
|
+
USERWHSCODE: sap_rep.USERWHSCODE,
|
|
139
|
+
id: `${nameSpace}_${sap_rep.USERID}`,
|
|
140
|
+
},
|
|
141
|
+
assigned_warehouse: warehouse,
|
|
142
|
+
company_namespace: [nameSpace],
|
|
143
|
+
};
|
|
144
|
+
if (!repzo_rep) {
|
|
145
|
+
// Create
|
|
146
|
+
try {
|
|
147
|
+
const created_rep = await repzo.rep.create(body);
|
|
148
|
+
result.created++;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
console.log(
|
|
151
|
+
"Create Rep Failed >> ",
|
|
152
|
+
e === null || e === void 0 ? void 0 : e.response,
|
|
153
|
+
body
|
|
154
|
+
);
|
|
155
|
+
failed_docs_report.push({
|
|
156
|
+
method: "create",
|
|
157
|
+
doc: body,
|
|
158
|
+
error_message: set_error(e),
|
|
159
|
+
});
|
|
160
|
+
result.failed++;
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
const found_identical_docs = db.search({
|
|
164
|
+
USERID: repzo_rep.integration_id,
|
|
165
|
+
USERDESC: repzo_rep.name,
|
|
166
|
+
DEPARTMENTCODE:
|
|
167
|
+
(_j = repzo_rep.integration_meta) === null || _j === void 0
|
|
168
|
+
? void 0
|
|
169
|
+
: _j.DEPARTMENTCODE,
|
|
170
|
+
USERCASHACCOUNT:
|
|
171
|
+
(_k = repzo_rep.integration_meta) === null || _k === void 0
|
|
172
|
+
? void 0
|
|
173
|
+
: _k.USERCASHACCOUNT,
|
|
174
|
+
USERCHECKACCTCODE:
|
|
175
|
+
(_l = repzo_rep.integration_meta) === null || _l === void 0
|
|
176
|
+
? void 0
|
|
177
|
+
: _l.USERCHECKACCTCODE,
|
|
178
|
+
USERWHSCODE:
|
|
179
|
+
(_m = repzo_rep.integration_meta) === null || _m === void 0
|
|
180
|
+
? void 0
|
|
181
|
+
: _m.USERWHSCODE,
|
|
182
|
+
});
|
|
183
|
+
if (found_identical_docs.length) continue;
|
|
184
|
+
// Update
|
|
185
|
+
try {
|
|
186
|
+
// Delete Rep.Password
|
|
187
|
+
delete body.password;
|
|
188
|
+
const updated_rep = await repzo.rep.update(repzo_rep._id, body);
|
|
189
|
+
result.updated++;
|
|
190
|
+
} catch (e) {
|
|
191
|
+
console.log(
|
|
192
|
+
"Update Rep Failed >> ",
|
|
193
|
+
(_o = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
194
|
+
_o === void 0
|
|
195
|
+
? void 0
|
|
196
|
+
: _o.data,
|
|
197
|
+
body
|
|
198
|
+
);
|
|
199
|
+
failed_docs_report.push({
|
|
200
|
+
method: "update",
|
|
201
|
+
doc_id:
|
|
202
|
+
repzo_rep === null || repzo_rep === void 0
|
|
203
|
+
? void 0
|
|
204
|
+
: repzo_rep._id,
|
|
205
|
+
doc: body,
|
|
206
|
+
error_message: set_error(e),
|
|
207
|
+
});
|
|
208
|
+
result.failed++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// console.log(result);
|
|
213
|
+
await update_bench_time(
|
|
214
|
+
repzo,
|
|
215
|
+
commandEvent.app._id,
|
|
216
|
+
bench_time_key,
|
|
217
|
+
new_bench_time
|
|
218
|
+
);
|
|
219
|
+
await commandLog
|
|
220
|
+
.setStatus(
|
|
221
|
+
"success",
|
|
222
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
223
|
+
)
|
|
224
|
+
.setBody(result)
|
|
225
|
+
.commit();
|
|
226
|
+
return result;
|
|
227
|
+
} catch (e) {
|
|
228
|
+
//@ts-ignore
|
|
229
|
+
console.error(
|
|
230
|
+
((_p = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
231
|
+
_p === void 0
|
|
232
|
+
? void 0
|
|
233
|
+
: _p.data) || e
|
|
234
|
+
);
|
|
235
|
+
await commandLog.setStatus("fail", e).commit();
|
|
236
|
+
throw e;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const get_sap_reps = async (serviceEndPoint, query) => {
|
|
240
|
+
try {
|
|
241
|
+
const sap_reps = await _create(serviceEndPoint, "/Users", {});
|
|
242
|
+
return sap_reps;
|
|
243
|
+
} catch (e) {
|
|
244
|
+
throw e;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
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_tag = async (commandEvent) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
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_tag");
|
|
21
|
+
const new_bench_time = new Date().toISOString();
|
|
22
|
+
const bench_time_key = "bench_time_tag";
|
|
23
|
+
await commandLog.load(commandEvent.sync_id);
|
|
24
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Tags").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_tags = await get_sap_tags(
|
|
35
|
+
commandEvent.app.formData.sapHostUrl,
|
|
36
|
+
{}
|
|
37
|
+
);
|
|
38
|
+
result.sap_total =
|
|
39
|
+
(_b =
|
|
40
|
+
sap_tags === null || sap_tags === void 0
|
|
41
|
+
? void 0
|
|
42
|
+
: sap_tags.Territories) === null || _b === void 0
|
|
43
|
+
? void 0
|
|
44
|
+
: _b.length;
|
|
45
|
+
await commandLog
|
|
46
|
+
.addDetail(`${result.sap_total} Territories in SAP`)
|
|
47
|
+
.commit();
|
|
48
|
+
const db = new DataSet([], { autoIndex: false });
|
|
49
|
+
db.createIndex({
|
|
50
|
+
TerritoryID: true,
|
|
51
|
+
Description: true,
|
|
52
|
+
});
|
|
53
|
+
db.load(
|
|
54
|
+
sap_tags === null || sap_tags === void 0 ? void 0 : sap_tags.Territories
|
|
55
|
+
);
|
|
56
|
+
const repzo_tags = await repzo.tag.find({ type: "area", per_page: 50000 });
|
|
57
|
+
result.repzo_total =
|
|
58
|
+
(_c =
|
|
59
|
+
repzo_tags === null || repzo_tags === void 0
|
|
60
|
+
? void 0
|
|
61
|
+
: repzo_tags.data) === null || _c === void 0
|
|
62
|
+
? void 0
|
|
63
|
+
: _c.length;
|
|
64
|
+
await commandLog
|
|
65
|
+
.addDetail(
|
|
66
|
+
`${
|
|
67
|
+
(_d =
|
|
68
|
+
repzo_tags === null || repzo_tags === void 0
|
|
69
|
+
? void 0
|
|
70
|
+
: repzo_tags.data) === null || _d === void 0
|
|
71
|
+
? void 0
|
|
72
|
+
: _d.length
|
|
73
|
+
} Area Tags in Repzo`
|
|
74
|
+
)
|
|
75
|
+
.commit();
|
|
76
|
+
for (
|
|
77
|
+
let i = 0;
|
|
78
|
+
i <
|
|
79
|
+
((_e =
|
|
80
|
+
sap_tags === null || sap_tags === void 0
|
|
81
|
+
? void 0
|
|
82
|
+
: sap_tags.Territories) === null || _e === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _e.length);
|
|
85
|
+
i++
|
|
86
|
+
) {
|
|
87
|
+
const sap_tag = sap_tags.Territories[i];
|
|
88
|
+
const repzo_tag = repzo_tags.data.find((r_tag) => {
|
|
89
|
+
var _a;
|
|
90
|
+
return (
|
|
91
|
+
((_a = r_tag.integration_meta) === null || _a === void 0
|
|
92
|
+
? void 0
|
|
93
|
+
: _a.id) == `${nameSpace}_${sap_tag.TerritoryID}`
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
const body = {
|
|
97
|
+
tag: sap_tag.Description,
|
|
98
|
+
type: "area",
|
|
99
|
+
disabled: false,
|
|
100
|
+
integration_meta: {
|
|
101
|
+
id: `${nameSpace}_${sap_tag.TerritoryID}`,
|
|
102
|
+
TerritoryID: sap_tag.TerritoryID,
|
|
103
|
+
},
|
|
104
|
+
company_namespace: [nameSpace],
|
|
105
|
+
};
|
|
106
|
+
if (!repzo_tag) {
|
|
107
|
+
// Create
|
|
108
|
+
try {
|
|
109
|
+
const created_tag = await repzo.tag.create(body);
|
|
110
|
+
result.created++;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.log(
|
|
113
|
+
"Create Tag Failed >> ",
|
|
114
|
+
e === null || e === void 0 ? void 0 : e.response,
|
|
115
|
+
body
|
|
116
|
+
);
|
|
117
|
+
failed_docs_report.push({
|
|
118
|
+
method: "create",
|
|
119
|
+
doc: body,
|
|
120
|
+
error_message: set_error(e),
|
|
121
|
+
});
|
|
122
|
+
result.failed++;
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
const found_identical_docs = db.search({
|
|
126
|
+
TerritoryID:
|
|
127
|
+
(_f = repzo_tag.integration_meta) === null || _f === void 0
|
|
128
|
+
? void 0
|
|
129
|
+
: _f.TerritoryID,
|
|
130
|
+
Description: repzo_tag.tag,
|
|
131
|
+
});
|
|
132
|
+
if (found_identical_docs.length) continue;
|
|
133
|
+
// Update
|
|
134
|
+
try {
|
|
135
|
+
const updated_tag = await repzo.tag.update(repzo_tag._id, body);
|
|
136
|
+
result.updated++;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.log(
|
|
139
|
+
"Update Tag Failed >> ",
|
|
140
|
+
(_g = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
141
|
+
_g === void 0
|
|
142
|
+
? void 0
|
|
143
|
+
: _g.data,
|
|
144
|
+
body
|
|
145
|
+
);
|
|
146
|
+
failed_docs_report.push({
|
|
147
|
+
method: "update",
|
|
148
|
+
doc_id:
|
|
149
|
+
repzo_tag === null || repzo_tag === void 0
|
|
150
|
+
? void 0
|
|
151
|
+
: repzo_tag._id,
|
|
152
|
+
doc: body,
|
|
153
|
+
error_message: set_error(e),
|
|
154
|
+
});
|
|
155
|
+
result.failed++;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// console.log(result);
|
|
160
|
+
await update_bench_time(
|
|
161
|
+
repzo,
|
|
162
|
+
commandEvent.app._id,
|
|
163
|
+
bench_time_key,
|
|
164
|
+
new_bench_time
|
|
165
|
+
);
|
|
166
|
+
await commandLog
|
|
167
|
+
.setStatus(
|
|
168
|
+
"success",
|
|
169
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
170
|
+
)
|
|
171
|
+
.setBody(result)
|
|
172
|
+
.commit();
|
|
173
|
+
return result;
|
|
174
|
+
} catch (e) {
|
|
175
|
+
//@ts-ignore
|
|
176
|
+
console.error(
|
|
177
|
+
((_h = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
178
|
+
_h === void 0
|
|
179
|
+
? void 0
|
|
180
|
+
: _h.data) || e
|
|
181
|
+
);
|
|
182
|
+
await commandLog.setStatus("fail", e).commit();
|
|
183
|
+
throw e;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const get_sap_tags = async (serviceEndPoint, query) => {
|
|
187
|
+
try {
|
|
188
|
+
const sap_tags = await _create(serviceEndPoint, "/Territories", {
|
|
189
|
+
Inactive: "N",
|
|
190
|
+
});
|
|
191
|
+
return sap_tags;
|
|
192
|
+
} catch (e) {
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
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_tax = async (commandEvent) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
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_tax");
|
|
21
|
+
const new_bench_time = new Date().toISOString();
|
|
22
|
+
const bench_time_key = "bench_time_tax";
|
|
23
|
+
await commandLog.load(commandEvent.sync_id);
|
|
24
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Taxes").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_taxes = await get_sap_taxes(
|
|
35
|
+
commandEvent.app.formData.sapHostUrl,
|
|
36
|
+
{}
|
|
37
|
+
);
|
|
38
|
+
result.sap_total =
|
|
39
|
+
(_b =
|
|
40
|
+
sap_taxes === null || sap_taxes === void 0
|
|
41
|
+
? void 0
|
|
42
|
+
: sap_taxes.Taxes) === null || _b === void 0
|
|
43
|
+
? void 0
|
|
44
|
+
: _b.length;
|
|
45
|
+
await commandLog.addDetail(`${result.sap_total} taxes in SAP`).commit();
|
|
46
|
+
const db = new DataSet([], { autoIndex: false });
|
|
47
|
+
db.createIndex({
|
|
48
|
+
TaxCode: true,
|
|
49
|
+
TaxName: true,
|
|
50
|
+
TaxRate: true,
|
|
51
|
+
type: "additive",
|
|
52
|
+
});
|
|
53
|
+
db.load(
|
|
54
|
+
sap_taxes === null || sap_taxes === void 0 ? void 0 : sap_taxes.Taxes
|
|
55
|
+
);
|
|
56
|
+
const repzo_taxes = await repzo.tax.find({ per_page: 50000 });
|
|
57
|
+
result.repzo_total =
|
|
58
|
+
(_c =
|
|
59
|
+
repzo_taxes === null || repzo_taxes === void 0
|
|
60
|
+
? void 0
|
|
61
|
+
: repzo_taxes.data) === null || _c === void 0
|
|
62
|
+
? void 0
|
|
63
|
+
: _c.length;
|
|
64
|
+
await commandLog
|
|
65
|
+
.addDetail(
|
|
66
|
+
`${
|
|
67
|
+
(_d =
|
|
68
|
+
repzo_taxes === null || repzo_taxes === void 0
|
|
69
|
+
? void 0
|
|
70
|
+
: repzo_taxes.data) === null || _d === void 0
|
|
71
|
+
? void 0
|
|
72
|
+
: _d.length
|
|
73
|
+
} taxes in Repzo`
|
|
74
|
+
)
|
|
75
|
+
.commit();
|
|
76
|
+
for (
|
|
77
|
+
let i = 0;
|
|
78
|
+
i <
|
|
79
|
+
((_e =
|
|
80
|
+
sap_taxes === null || sap_taxes === void 0
|
|
81
|
+
? void 0
|
|
82
|
+
: sap_taxes.Taxes) === null || _e === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _e.length);
|
|
85
|
+
i++
|
|
86
|
+
) {
|
|
87
|
+
const sap_tax = sap_taxes.Taxes[i];
|
|
88
|
+
const repzo_tax = repzo_taxes.data.find((r_tax) => {
|
|
89
|
+
var _a;
|
|
90
|
+
return (
|
|
91
|
+
((_a = r_tax.integration_meta) === null || _a === void 0
|
|
92
|
+
? void 0
|
|
93
|
+
: _a.id) == `${nameSpace}_${sap_tax.TaxCode}`
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
const body = {
|
|
97
|
+
name: sap_tax.TaxName,
|
|
98
|
+
rate: Number(sap_tax.TaxRate / 100),
|
|
99
|
+
type: "additive",
|
|
100
|
+
disabled: sap_tax.Inactive === "N" ? false : true,
|
|
101
|
+
integration_meta: {
|
|
102
|
+
id: `${nameSpace}_${sap_tax.TaxCode}`,
|
|
103
|
+
TaxCode: sap_tax.TaxCode,
|
|
104
|
+
},
|
|
105
|
+
company_namespace: [nameSpace],
|
|
106
|
+
};
|
|
107
|
+
if (!repzo_tax) {
|
|
108
|
+
// Create
|
|
109
|
+
try {
|
|
110
|
+
const created_tax = await repzo.tax.create(body);
|
|
111
|
+
result.created++;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
console.log(
|
|
114
|
+
"Create Tax Failed >> ",
|
|
115
|
+
e === null || e === void 0 ? void 0 : e.response,
|
|
116
|
+
body
|
|
117
|
+
);
|
|
118
|
+
failed_docs_report.push({
|
|
119
|
+
method: "create",
|
|
120
|
+
doc: body,
|
|
121
|
+
error_message: set_error(e),
|
|
122
|
+
});
|
|
123
|
+
result.failed++;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
const found_identical_docs = db.search({
|
|
127
|
+
TaxCode:
|
|
128
|
+
(_f = repzo_tax.integration_meta) === null || _f === void 0
|
|
129
|
+
? void 0
|
|
130
|
+
: _f.TaxCode,
|
|
131
|
+
TaxName: repzo_tax.name,
|
|
132
|
+
TaxRate: repzo_tax.rate * 100,
|
|
133
|
+
type: repzo_tax.type,
|
|
134
|
+
});
|
|
135
|
+
if (found_identical_docs.length) continue;
|
|
136
|
+
// Update
|
|
137
|
+
try {
|
|
138
|
+
const updated_tax = await repzo.tax.update(repzo_tax._id, body);
|
|
139
|
+
result.updated++;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.log(
|
|
142
|
+
"Update Tax Failed >> ",
|
|
143
|
+
(_g = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
144
|
+
_g === void 0
|
|
145
|
+
? void 0
|
|
146
|
+
: _g.data,
|
|
147
|
+
body
|
|
148
|
+
);
|
|
149
|
+
failed_docs_report.push({
|
|
150
|
+
method: "update",
|
|
151
|
+
doc_id:
|
|
152
|
+
repzo_tax === null || repzo_tax === void 0
|
|
153
|
+
? void 0
|
|
154
|
+
: repzo_tax._id,
|
|
155
|
+
doc: body,
|
|
156
|
+
error_message: set_error(e),
|
|
157
|
+
});
|
|
158
|
+
result.failed++;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// console.log(result);
|
|
163
|
+
await update_bench_time(
|
|
164
|
+
repzo,
|
|
165
|
+
commandEvent.app._id,
|
|
166
|
+
bench_time_key,
|
|
167
|
+
new_bench_time
|
|
168
|
+
);
|
|
169
|
+
await commandLog
|
|
170
|
+
.setStatus(
|
|
171
|
+
"success",
|
|
172
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
173
|
+
)
|
|
174
|
+
.setBody(result)
|
|
175
|
+
.commit();
|
|
176
|
+
return result;
|
|
177
|
+
} catch (e) {
|
|
178
|
+
//@ts-ignore
|
|
179
|
+
console.error(
|
|
180
|
+
((_h = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
181
|
+
_h === void 0
|
|
182
|
+
? void 0
|
|
183
|
+
: _h.data) || e
|
|
184
|
+
);
|
|
185
|
+
await commandLog.setStatus("fail", e).commit();
|
|
186
|
+
throw e;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const get_sap_taxes = async (serviceEndPoint, query) => {
|
|
190
|
+
try {
|
|
191
|
+
const sap_taxes = await _create(serviceEndPoint, "/Taxes", {
|
|
192
|
+
Inactive: "N",
|
|
193
|
+
});
|
|
194
|
+
return sap_taxes;
|
|
195
|
+
} catch (e) {
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
};
|