repzo-sap-absjo 1.0.10 → 1.0.12
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 +2 -0
- package/lib/actions/create_invoice.d.ts +19 -13
- package/lib/actions/create_invoice.js +356 -208
- package/lib/actions/create_payment.d.ts +4 -1
- package/lib/actions/create_payment.js +191 -117
- package/lib/actions/create_proforma.d.ts +4 -1
- package/lib/actions/create_proforma.js +285 -155
- package/lib/actions/create_return_invoice.d.ts +4 -1
- package/lib/actions/create_return_invoice.js +312 -169
- package/lib/actions/create_transfer.d.ts +4 -1
- package/lib/actions/create_transfer.js +223 -136
- 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 +66 -47
- 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 +15 -11
- package/lib/commands/index.js +60 -60
- 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 +612 -326
- package/lib/commands/product.d.ts +32 -30
- package/lib/commands/product.js +426 -243
- package/lib/commands/product_disabled.d.ts +3 -1
- package/lib/commands/product_disabled.js +164 -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 +21 -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 +328 -327
- 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/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 +83 -60
- package/lib/util.d.ts +70 -19
- package/lib/util.js +170 -144
- package/package.json +2 -2
- package/src/actions/create_invoice.ts +11 -16
- package/src/actions/create_payment.ts +11 -16
- package/src/actions/create_proforma.ts +19 -24
- package/src/actions/create_return_invoice.ts +11 -16
- package/src/actions/create_transfer.ts +23 -28
- package/src/commands/product.ts +1 -0
package/lib/commands/tag.js
CHANGED
|
@@ -1,119 +1,184 @@
|
|
|
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_tag = async (commandEvent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
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,
|
|
8
52
|
});
|
|
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
|
-
|
|
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("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,
|
|
34
127
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
}
|
|
128
|
+
if (found_identical_docs.length) continue;
|
|
129
|
+
// Update
|
|
130
|
+
try {
|
|
131
|
+
const updated_tag = await repzo.tag.update(repzo_tag._id, body);
|
|
132
|
+
result.updated++;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
// console.log("Update Tag Failed >> ", e?.response?.data, body);
|
|
135
|
+
failed_docs_report.push({
|
|
136
|
+
method: "update",
|
|
137
|
+
doc_id:
|
|
138
|
+
repzo_tag === null || repzo_tag === void 0
|
|
139
|
+
? void 0
|
|
140
|
+
: repzo_tag._id,
|
|
141
|
+
doc: body,
|
|
142
|
+
error_message: set_error(e),
|
|
143
|
+
});
|
|
144
|
+
result.failed++;
|
|
93
145
|
}
|
|
94
|
-
|
|
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;
|
|
146
|
+
}
|
|
107
147
|
}
|
|
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
|
+
}
|
|
108
174
|
};
|
|
109
175
|
const get_sap_tags = async (serviceEndPoint, query) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
176
|
+
try {
|
|
177
|
+
const sap_tags = await _create(serviceEndPoint, "/Territories", {
|
|
178
|
+
Inactive: "N",
|
|
179
|
+
});
|
|
180
|
+
return sap_tags;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
119
184
|
};
|
package/lib/commands/tax.js
CHANGED
|
@@ -1,122 +1,187 @@
|
|
|
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_tax = async (commandEvent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
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",
|
|
8
52
|
});
|
|
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
|
-
|
|
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("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,
|
|
34
130
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
}
|
|
131
|
+
if (found_identical_docs.length) continue;
|
|
132
|
+
// Update
|
|
133
|
+
try {
|
|
134
|
+
const updated_tax = await repzo.tax.update(repzo_tax._id, body);
|
|
135
|
+
result.updated++;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
// console.log("Update Tax Failed >> ", e?.response?.data, body);
|
|
138
|
+
failed_docs_report.push({
|
|
139
|
+
method: "update",
|
|
140
|
+
doc_id:
|
|
141
|
+
repzo_tax === null || repzo_tax === void 0
|
|
142
|
+
? void 0
|
|
143
|
+
: repzo_tax._id,
|
|
144
|
+
doc: body,
|
|
145
|
+
error_message: set_error(e),
|
|
146
|
+
});
|
|
147
|
+
result.failed++;
|
|
96
148
|
}
|
|
97
|
-
|
|
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;
|
|
149
|
+
}
|
|
110
150
|
}
|
|
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
|
+
}
|
|
111
177
|
};
|
|
112
178
|
const get_sap_taxes = async (serviceEndPoint, query) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
179
|
+
try {
|
|
180
|
+
const sap_taxes = await _create(serviceEndPoint, "/Taxes", {
|
|
181
|
+
Inactive: "N",
|
|
182
|
+
});
|
|
183
|
+
return sap_taxes;
|
|
184
|
+
} catch (e) {
|
|
185
|
+
throw e;
|
|
186
|
+
}
|
|
122
187
|
};
|