repzo-sap-absjo 1.0.6 → 1.0.8
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 +4 -0
- package/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +216 -336
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +125 -171
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +165 -268
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +177 -295
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +143 -198
- package/lib/actions/index.js +15 -23
- package/lib/commands/adjust_inventory.d.ts +2 -4
- package/lib/commands/adjust_inventory.js +160 -290
- package/lib/commands/bank.d.ts +2 -4
- package/lib/commands/bank.js +157 -279
- package/lib/commands/basic.js +47 -66
- package/lib/commands/category.d.ts +1 -3
- package/lib/commands/category.js +104 -178
- package/lib/commands/channel.d.ts +1 -3
- package/lib/commands/channel.js +117 -198
- package/lib/commands/client.d.ts +32 -34
- package/lib/commands/client.js +244 -404
- package/lib/commands/client_disabled.d.ts +1 -3
- package/lib/commands/client_disabled.js +94 -163
- package/lib/commands/index.d.ts +11 -15
- package/lib/commands/index.js +60 -60
- package/lib/commands/join.js +66 -192
- package/lib/commands/measureunit.d.ts +14 -19
- package/lib/commands/measureunit.js +191 -289
- package/lib/commands/measureunit_family.d.ts +8 -10
- package/lib/commands/measureunit_family.js +138 -250
- package/lib/commands/payment_term.d.ts +1 -3
- package/lib/commands/payment_term.js +123 -202
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +327 -571
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +243 -425
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -164
- package/lib/commands/rep.js +141 -221
- package/lib/commands/tag.js +109 -174
- package/lib/commands/tax.js +112 -177
- package/lib/commands/warehouse.d.ts +1 -3
- package/lib/commands/warehouse.js +119 -207
- package/lib/index.d.ts +12 -21
- package/lib/test/actions/create_invoice.js +188 -193
- package/lib/test/actions/create_payment.js +107 -112
- package/lib/test/actions/create_proforma.js +216 -220
- package/lib/test/actions/create_return_invoice.js +200 -205
- package/lib/test/actions/create_transfer.js +115 -120
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +327 -328
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +353 -355
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +327 -328
- 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 -90
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +344 -346
- 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 +60 -83
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +35 -0
- package/src/actions/create_payment.ts +35 -0
- package/src/actions/create_proforma.ts +35 -0
- package/src/actions/create_return_invoice.ts +35 -0
- package/src/actions/create_transfer.ts +34 -0
- package/src/commands/price_list.ts +40 -4
- package/src/test/commands/price_list.ts +263 -13
package/lib/commands/tag.js
CHANGED
|
@@ -1,184 +1,119 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
2
|
import DataSet from "data-set-query";
|
|
3
|
-
import { _create, update_bench_time, set_error } from "../util.js";
|
|
3
|
+
import { _create, update_bench_time, set_error, } from "../util.js";
|
|
4
4
|
export const sync_tag = async (commandEvent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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,
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
7
|
+
env: commandEvent.env,
|
|
52
8
|
});
|
|
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
|
-
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("Create Tag Failed >> ", e?.response, body);
|
|
113
|
-
failed_docs_report.push({
|
|
114
|
-
method: "create",
|
|
115
|
-
doc: body,
|
|
116
|
-
error_message: set_error(e),
|
|
117
|
-
});
|
|
118
|
-
result.failed++;
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
const found_identical_docs = db.search({
|
|
122
|
-
TerritoryID:
|
|
123
|
-
(_f = repzo_tag.integration_meta) === null || _f === void 0
|
|
124
|
-
? void 0
|
|
125
|
-
: _f.TerritoryID,
|
|
126
|
-
Description: repzo_tag.tag,
|
|
9
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
10
|
+
try {
|
|
11
|
+
// console.log("sync_tag");
|
|
12
|
+
const new_bench_time = new Date().toISOString();
|
|
13
|
+
const bench_time_key = "bench_time_tag";
|
|
14
|
+
await commandLog.load(commandEvent.sync_id);
|
|
15
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Tags").commit();
|
|
16
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
17
|
+
const result = {
|
|
18
|
+
sap_total: 0,
|
|
19
|
+
repzo_total: 0,
|
|
20
|
+
created: 0,
|
|
21
|
+
updated: 0,
|
|
22
|
+
failed: 0,
|
|
23
|
+
};
|
|
24
|
+
const failed_docs_report = [];
|
|
25
|
+
const sap_tags = await get_sap_tags(commandEvent.app.formData.sapHostUrl, {});
|
|
26
|
+
result.sap_total = (_b = sap_tags === null || sap_tags === void 0 ? void 0 : sap_tags.Territories) === null || _b === void 0 ? void 0 : _b.length;
|
|
27
|
+
await commandLog
|
|
28
|
+
.addDetail(`${result.sap_total} Territories in SAP`)
|
|
29
|
+
.commit();
|
|
30
|
+
const db = new DataSet([], { autoIndex: false });
|
|
31
|
+
db.createIndex({
|
|
32
|
+
TerritoryID: true,
|
|
33
|
+
Description: true,
|
|
127
34
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
35
|
+
db.load(sap_tags === null || sap_tags === void 0 ? void 0 : sap_tags.Territories);
|
|
36
|
+
const repzo_tags = await repzo.tag.find({ type: "area", per_page: 50000 });
|
|
37
|
+
result.repzo_total = (_c = repzo_tags === null || repzo_tags === void 0 ? void 0 : repzo_tags.data) === null || _c === void 0 ? void 0 : _c.length;
|
|
38
|
+
await commandLog
|
|
39
|
+
.addDetail(`${(_d = repzo_tags === null || repzo_tags === void 0 ? void 0 : repzo_tags.data) === null || _d === void 0 ? void 0 : _d.length} Area Tags in Repzo`)
|
|
40
|
+
.commit();
|
|
41
|
+
for (let i = 0; i < ((_e = sap_tags === null || sap_tags === void 0 ? void 0 : sap_tags.Territories) === null || _e === void 0 ? void 0 : _e.length); i++) {
|
|
42
|
+
const sap_tag = sap_tags.Territories[i];
|
|
43
|
+
const repzo_tag = repzo_tags.data.find((r_tag) => { var _a; return ((_a = r_tag.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_tag.TerritoryID}`; });
|
|
44
|
+
const body = {
|
|
45
|
+
tag: sap_tag.Description,
|
|
46
|
+
type: "area",
|
|
47
|
+
disabled: false,
|
|
48
|
+
integration_meta: {
|
|
49
|
+
id: `${nameSpace}_${sap_tag.TerritoryID}`,
|
|
50
|
+
TerritoryID: sap_tag.TerritoryID,
|
|
51
|
+
},
|
|
52
|
+
company_namespace: [nameSpace],
|
|
53
|
+
};
|
|
54
|
+
if (!repzo_tag) {
|
|
55
|
+
// Create
|
|
56
|
+
try {
|
|
57
|
+
const created_tag = await repzo.tag.create(body);
|
|
58
|
+
result.created++;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
// console.log("Create Tag Failed >> ", e?.response, body);
|
|
62
|
+
failed_docs_report.push({
|
|
63
|
+
method: "create",
|
|
64
|
+
doc: body,
|
|
65
|
+
error_message: set_error(e),
|
|
66
|
+
});
|
|
67
|
+
result.failed++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const found_identical_docs = db.search({
|
|
72
|
+
TerritoryID: (_f = repzo_tag.integration_meta) === null || _f === void 0 ? void 0 : _f.TerritoryID,
|
|
73
|
+
Description: repzo_tag.tag,
|
|
74
|
+
});
|
|
75
|
+
if (found_identical_docs.length)
|
|
76
|
+
continue;
|
|
77
|
+
// Update
|
|
78
|
+
try {
|
|
79
|
+
const updated_tag = await repzo.tag.update(repzo_tag._id, body);
|
|
80
|
+
result.updated++;
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
// console.log("Update Tag Failed >> ", e?.response?.data, body);
|
|
84
|
+
failed_docs_report.push({
|
|
85
|
+
method: "update",
|
|
86
|
+
doc_id: repzo_tag === null || repzo_tag === void 0 ? void 0 : repzo_tag._id,
|
|
87
|
+
doc: body,
|
|
88
|
+
error_message: set_error(e),
|
|
89
|
+
});
|
|
90
|
+
result.failed++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
145
93
|
}
|
|
146
|
-
|
|
94
|
+
// console.log(result);
|
|
95
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
96
|
+
await commandLog
|
|
97
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
98
|
+
.setBody(result)
|
|
99
|
+
.commit();
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
//@ts-ignore
|
|
104
|
+
console.error(((_g = e === null || e === void 0 ? void 0 : e.response) === null || _g === void 0 ? void 0 : _g.data) || e);
|
|
105
|
+
await commandLog.setStatus("fail", e).commit();
|
|
106
|
+
throw e;
|
|
147
107
|
}
|
|
148
|
-
// console.log(result);
|
|
149
|
-
await update_bench_time(
|
|
150
|
-
repzo,
|
|
151
|
-
commandEvent.app._id,
|
|
152
|
-
bench_time_key,
|
|
153
|
-
new_bench_time
|
|
154
|
-
);
|
|
155
|
-
await commandLog
|
|
156
|
-
.setStatus(
|
|
157
|
-
"success",
|
|
158
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
159
|
-
)
|
|
160
|
-
.setBody(result)
|
|
161
|
-
.commit();
|
|
162
|
-
return result;
|
|
163
|
-
} catch (e) {
|
|
164
|
-
//@ts-ignore
|
|
165
|
-
console.error(
|
|
166
|
-
((_g = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
167
|
-
_g === void 0
|
|
168
|
-
? void 0
|
|
169
|
-
: _g.data) || e
|
|
170
|
-
);
|
|
171
|
-
await commandLog.setStatus("fail", e).commit();
|
|
172
|
-
throw e;
|
|
173
|
-
}
|
|
174
108
|
};
|
|
175
109
|
const get_sap_tags = async (serviceEndPoint, query) => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
110
|
+
try {
|
|
111
|
+
const sap_tags = await _create(serviceEndPoint, "/Territories", {
|
|
112
|
+
Inactive: "N",
|
|
113
|
+
});
|
|
114
|
+
return sap_tags;
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
184
119
|
};
|
package/lib/commands/tax.js
CHANGED
|
@@ -1,187 +1,122 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
2
|
import DataSet from "data-set-query";
|
|
3
|
-
import { _create, update_bench_time, set_error } from "../util.js";
|
|
3
|
+
import { _create, update_bench_time, set_error, } from "../util.js";
|
|
4
4
|
export const sync_tax = async (commandEvent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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",
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
7
|
+
env: commandEvent.env,
|
|
52
8
|
});
|
|
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
|
-
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("Create Tax Failed >> ", e?.response, body);
|
|
114
|
-
failed_docs_report.push({
|
|
115
|
-
method: "create",
|
|
116
|
-
doc: body,
|
|
117
|
-
error_message: set_error(e),
|
|
118
|
-
});
|
|
119
|
-
result.failed++;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
const found_identical_docs = db.search({
|
|
123
|
-
TaxCode:
|
|
124
|
-
(_f = repzo_tax.integration_meta) === null || _f === void 0
|
|
125
|
-
? void 0
|
|
126
|
-
: _f.TaxCode,
|
|
127
|
-
TaxName: repzo_tax.name,
|
|
128
|
-
TaxRate: repzo_tax.rate * 100,
|
|
129
|
-
type: repzo_tax.type,
|
|
9
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
10
|
+
try {
|
|
11
|
+
// console.log("sync_tax");
|
|
12
|
+
const new_bench_time = new Date().toISOString();
|
|
13
|
+
const bench_time_key = "bench_time_tax";
|
|
14
|
+
await commandLog.load(commandEvent.sync_id);
|
|
15
|
+
await commandLog.addDetail("Repzo SAP: Started Syncing Taxes").commit();
|
|
16
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
17
|
+
const result = {
|
|
18
|
+
sap_total: 0,
|
|
19
|
+
repzo_total: 0,
|
|
20
|
+
created: 0,
|
|
21
|
+
updated: 0,
|
|
22
|
+
failed: 0,
|
|
23
|
+
};
|
|
24
|
+
const failed_docs_report = [];
|
|
25
|
+
const sap_taxes = await get_sap_taxes(commandEvent.app.formData.sapHostUrl, {});
|
|
26
|
+
result.sap_total = (_b = sap_taxes === null || sap_taxes === void 0 ? void 0 : sap_taxes.Taxes) === null || _b === void 0 ? void 0 : _b.length;
|
|
27
|
+
await commandLog.addDetail(`${result.sap_total} taxes in SAP`).commit();
|
|
28
|
+
const db = new DataSet([], { autoIndex: false });
|
|
29
|
+
db.createIndex({
|
|
30
|
+
TaxCode: true,
|
|
31
|
+
TaxName: true,
|
|
32
|
+
TaxRate: true,
|
|
33
|
+
type: "additive",
|
|
130
34
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
35
|
+
db.load(sap_taxes === null || sap_taxes === void 0 ? void 0 : sap_taxes.Taxes);
|
|
36
|
+
const repzo_taxes = await repzo.tax.find({ per_page: 50000 });
|
|
37
|
+
result.repzo_total = (_c = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _c === void 0 ? void 0 : _c.length;
|
|
38
|
+
await commandLog
|
|
39
|
+
.addDetail(`${(_d = repzo_taxes === null || repzo_taxes === void 0 ? void 0 : repzo_taxes.data) === null || _d === void 0 ? void 0 : _d.length} taxes in Repzo`)
|
|
40
|
+
.commit();
|
|
41
|
+
for (let i = 0; i < ((_e = sap_taxes === null || sap_taxes === void 0 ? void 0 : sap_taxes.Taxes) === null || _e === void 0 ? void 0 : _e.length); i++) {
|
|
42
|
+
const sap_tax = sap_taxes.Taxes[i];
|
|
43
|
+
const repzo_tax = repzo_taxes.data.find((r_tax) => { var _a; return ((_a = r_tax.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_tax.TaxCode}`; });
|
|
44
|
+
const body = {
|
|
45
|
+
name: sap_tax.TaxName,
|
|
46
|
+
rate: Number(sap_tax.TaxRate / 100),
|
|
47
|
+
type: "additive",
|
|
48
|
+
disabled: sap_tax.Inactive === "N" ? false : true,
|
|
49
|
+
integration_meta: {
|
|
50
|
+
id: `${nameSpace}_${sap_tax.TaxCode}`,
|
|
51
|
+
TaxCode: sap_tax.TaxCode,
|
|
52
|
+
},
|
|
53
|
+
company_namespace: [nameSpace],
|
|
54
|
+
};
|
|
55
|
+
if (!repzo_tax) {
|
|
56
|
+
// Create
|
|
57
|
+
try {
|
|
58
|
+
const created_tax = await repzo.tax.create(body);
|
|
59
|
+
result.created++;
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
// console.log("Create Tax Failed >> ", e?.response, body);
|
|
63
|
+
failed_docs_report.push({
|
|
64
|
+
method: "create",
|
|
65
|
+
doc: body,
|
|
66
|
+
error_message: set_error(e),
|
|
67
|
+
});
|
|
68
|
+
result.failed++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const found_identical_docs = db.search({
|
|
73
|
+
TaxCode: (_f = repzo_tax.integration_meta) === null || _f === void 0 ? void 0 : _f.TaxCode,
|
|
74
|
+
TaxName: repzo_tax.name,
|
|
75
|
+
TaxRate: repzo_tax.rate * 100,
|
|
76
|
+
type: repzo_tax.type,
|
|
77
|
+
});
|
|
78
|
+
if (found_identical_docs.length)
|
|
79
|
+
continue;
|
|
80
|
+
// Update
|
|
81
|
+
try {
|
|
82
|
+
const updated_tax = await repzo.tax.update(repzo_tax._id, body);
|
|
83
|
+
result.updated++;
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
// console.log("Update Tax Failed >> ", e?.response?.data, body);
|
|
87
|
+
failed_docs_report.push({
|
|
88
|
+
method: "update",
|
|
89
|
+
doc_id: repzo_tax === null || repzo_tax === void 0 ? void 0 : repzo_tax._id,
|
|
90
|
+
doc: body,
|
|
91
|
+
error_message: set_error(e),
|
|
92
|
+
});
|
|
93
|
+
result.failed++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
148
96
|
}
|
|
149
|
-
|
|
97
|
+
// console.log(result);
|
|
98
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
99
|
+
await commandLog
|
|
100
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
101
|
+
.setBody(result)
|
|
102
|
+
.commit();
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
//@ts-ignore
|
|
107
|
+
console.error(((_g = e === null || e === void 0 ? void 0 : e.response) === null || _g === void 0 ? void 0 : _g.data) || e);
|
|
108
|
+
await commandLog.setStatus("fail", e).commit();
|
|
109
|
+
throw e;
|
|
150
110
|
}
|
|
151
|
-
// console.log(result);
|
|
152
|
-
await update_bench_time(
|
|
153
|
-
repzo,
|
|
154
|
-
commandEvent.app._id,
|
|
155
|
-
bench_time_key,
|
|
156
|
-
new_bench_time
|
|
157
|
-
);
|
|
158
|
-
await commandLog
|
|
159
|
-
.setStatus(
|
|
160
|
-
"success",
|
|
161
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
162
|
-
)
|
|
163
|
-
.setBody(result)
|
|
164
|
-
.commit();
|
|
165
|
-
return result;
|
|
166
|
-
} catch (e) {
|
|
167
|
-
//@ts-ignore
|
|
168
|
-
console.error(
|
|
169
|
-
((_g = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
170
|
-
_g === void 0
|
|
171
|
-
? void 0
|
|
172
|
-
: _g.data) || e
|
|
173
|
-
);
|
|
174
|
-
await commandLog.setStatus("fail", e).commit();
|
|
175
|
-
throw e;
|
|
176
|
-
}
|
|
177
111
|
};
|
|
178
112
|
const get_sap_taxes = async (serviceEndPoint, query) => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
113
|
+
try {
|
|
114
|
+
const sap_taxes = await _create(serviceEndPoint, "/Taxes", {
|
|
115
|
+
Inactive: "N",
|
|
116
|
+
});
|
|
117
|
+
return sap_taxes;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
187
122
|
};
|