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,263 @@
|
|
|
1
|
+
import Repzo from "repzo";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import { update_bench_time, set_error } from "../util.js";
|
|
4
|
+
import { get_sap_UoMs } from "./measureunit.js";
|
|
5
|
+
export const sync_measureunit_family = async (commandEvent) => {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
7
|
+
const repzo = new Repzo(
|
|
8
|
+
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
9
|
+
? void 0
|
|
10
|
+
: _a.repzoApiKey,
|
|
11
|
+
{
|
|
12
|
+
env: commandEvent.env,
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
const commandLog = new Repzo.CommandLog(
|
|
16
|
+
repzo,
|
|
17
|
+
commandEvent.app,
|
|
18
|
+
commandEvent.command
|
|
19
|
+
);
|
|
20
|
+
try {
|
|
21
|
+
console.log("sync_measureunit_family");
|
|
22
|
+
const new_bench_time = new Date().toISOString();
|
|
23
|
+
const bench_time_key = "bench_time_measureunit_family";
|
|
24
|
+
await commandLog.load(commandEvent.sync_id);
|
|
25
|
+
await commandLog
|
|
26
|
+
.addDetail("Repzo SAP: Started Syncing Measure Units Family")
|
|
27
|
+
.commit();
|
|
28
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
29
|
+
const result = {
|
|
30
|
+
sap_total: 0,
|
|
31
|
+
repzo_total: 0,
|
|
32
|
+
sap_UoM_total: 0,
|
|
33
|
+
repzo_UoM_total: 0,
|
|
34
|
+
created: 0,
|
|
35
|
+
updated: 0,
|
|
36
|
+
failed: 0,
|
|
37
|
+
};
|
|
38
|
+
const failed_docs_report = [];
|
|
39
|
+
const sap_UoMs = await get_sap_UoMs(
|
|
40
|
+
commandEvent.app.formData.sapHostUrl,
|
|
41
|
+
{}
|
|
42
|
+
);
|
|
43
|
+
result.sap_UoM_total =
|
|
44
|
+
sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length;
|
|
45
|
+
await commandLog
|
|
46
|
+
.addDetail(`${result.sap_UoM_total} Unit of Measures in SAP`)
|
|
47
|
+
.commit();
|
|
48
|
+
let repzo_UoMs = await repzo.measureunit.find({
|
|
49
|
+
disabled: false,
|
|
50
|
+
per_page: 50000,
|
|
51
|
+
});
|
|
52
|
+
result.repzo_UoM_total =
|
|
53
|
+
(_b =
|
|
54
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
55
|
+
? void 0
|
|
56
|
+
: repzo_UoMs.data) === null || _b === void 0
|
|
57
|
+
? void 0
|
|
58
|
+
: _b.length;
|
|
59
|
+
await commandLog
|
|
60
|
+
.addDetail(
|
|
61
|
+
`${
|
|
62
|
+
(_c =
|
|
63
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
64
|
+
? void 0
|
|
65
|
+
: repzo_UoMs.data) === null || _c === void 0
|
|
66
|
+
? void 0
|
|
67
|
+
: _c.length
|
|
68
|
+
} Measure Units in Repzo`
|
|
69
|
+
)
|
|
70
|
+
.commit();
|
|
71
|
+
if (
|
|
72
|
+
!((_d =
|
|
73
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
74
|
+
? void 0
|
|
75
|
+
: repzo_UoMs.data) === null || _d === void 0
|
|
76
|
+
? void 0
|
|
77
|
+
: _d.length)
|
|
78
|
+
) {
|
|
79
|
+
throw "measure units are not found or the nameSpace has more than one";
|
|
80
|
+
}
|
|
81
|
+
repzo_UoMs.data =
|
|
82
|
+
(_e = repzo_UoMs.data) === null || _e === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _e.filter((UoM) => UoM.integration_meta);
|
|
85
|
+
const repzo_UoMs_family = await repzo.measureunitFamily.find({
|
|
86
|
+
disabled: false,
|
|
87
|
+
per_page: 50000,
|
|
88
|
+
});
|
|
89
|
+
result.repzo_total =
|
|
90
|
+
(_f =
|
|
91
|
+
repzo_UoMs_family === null || repzo_UoMs_family === void 0
|
|
92
|
+
? void 0
|
|
93
|
+
: repzo_UoMs_family.data) === null || _f === void 0
|
|
94
|
+
? void 0
|
|
95
|
+
: _f.length;
|
|
96
|
+
await commandLog
|
|
97
|
+
.addDetail(
|
|
98
|
+
`${
|
|
99
|
+
(_g =
|
|
100
|
+
repzo_UoMs_family === null || repzo_UoMs_family === void 0
|
|
101
|
+
? void 0
|
|
102
|
+
: repzo_UoMs_family.data) === null || _g === void 0
|
|
103
|
+
? void 0
|
|
104
|
+
: _g.length
|
|
105
|
+
} Measure Units Family in Repzo`
|
|
106
|
+
)
|
|
107
|
+
.commit();
|
|
108
|
+
const sap_unique_family = {};
|
|
109
|
+
for (
|
|
110
|
+
let i = 0;
|
|
111
|
+
i < (sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length);
|
|
112
|
+
i++
|
|
113
|
+
) {
|
|
114
|
+
const sap_UoM = sap_UoMs[i];
|
|
115
|
+
const key = sap_UoM.ITEMCODE;
|
|
116
|
+
if (!sap_unique_family[key]) sap_unique_family[key] = {};
|
|
117
|
+
const uom_key = `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`;
|
|
118
|
+
sap_unique_family[key][uom_key] = 1;
|
|
119
|
+
}
|
|
120
|
+
result.sap_total =
|
|
121
|
+
(_h = Object.keys(sap_unique_family)) === null || _h === void 0
|
|
122
|
+
? void 0
|
|
123
|
+
: _h.length;
|
|
124
|
+
await commandLog
|
|
125
|
+
.addDetail(`${result.sap_total} Measure Units Family in SAP`)
|
|
126
|
+
.commit();
|
|
127
|
+
for (let key in sap_unique_family) {
|
|
128
|
+
const sap_family = sap_unique_family[key];
|
|
129
|
+
const repzo_family = repzo_UoMs_family.data.find((r_family) => {
|
|
130
|
+
var _a;
|
|
131
|
+
return (
|
|
132
|
+
((_a = r_family.integration_meta) === null || _a === void 0
|
|
133
|
+
? void 0
|
|
134
|
+
: _a.id) == `${nameSpace}_${key}`
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
let measureunits = [];
|
|
138
|
+
Object.keys(sap_family).forEach((unit) => {
|
|
139
|
+
var _a;
|
|
140
|
+
{
|
|
141
|
+
const UoM =
|
|
142
|
+
(_a =
|
|
143
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
144
|
+
? void 0
|
|
145
|
+
: repzo_UoMs.data) === null || _a === void 0
|
|
146
|
+
? void 0
|
|
147
|
+
: _a.find((repzo_uom) => {
|
|
148
|
+
var _a;
|
|
149
|
+
return (
|
|
150
|
+
((_a =
|
|
151
|
+
repzo_uom === null || repzo_uom === void 0
|
|
152
|
+
? void 0
|
|
153
|
+
: repzo_uom.integration_meta) === null || _a === void 0
|
|
154
|
+
? void 0
|
|
155
|
+
: _a.id) == unit
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
if (UoM) {
|
|
159
|
+
measureunits.push(UoM._id.toString());
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const body = {
|
|
164
|
+
name: key,
|
|
165
|
+
disabled: false,
|
|
166
|
+
integration_meta: { id: `${nameSpace}_${key}` },
|
|
167
|
+
measureunits: measureunits || [],
|
|
168
|
+
company_namespace: [nameSpace],
|
|
169
|
+
};
|
|
170
|
+
if (!repzo_family) {
|
|
171
|
+
// Create
|
|
172
|
+
try {
|
|
173
|
+
const created_UoM = await repzo.measureunitFamily.create(body);
|
|
174
|
+
result.created++;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.log(
|
|
177
|
+
"Create Measure Unit Family Failed >> ",
|
|
178
|
+
e === null || e === void 0 ? void 0 : e.response,
|
|
179
|
+
body
|
|
180
|
+
);
|
|
181
|
+
failed_docs_report.push({
|
|
182
|
+
method: "create",
|
|
183
|
+
doc: body,
|
|
184
|
+
error_message: set_error(e),
|
|
185
|
+
});
|
|
186
|
+
result.failed++;
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
if (
|
|
190
|
+
repzo_family.name == body.name &&
|
|
191
|
+
!((_k = _.difference(
|
|
192
|
+
((_j =
|
|
193
|
+
repzo_family === null || repzo_family === void 0
|
|
194
|
+
? void 0
|
|
195
|
+
: repzo_family.measureunits) === null || _j === void 0
|
|
196
|
+
? void 0
|
|
197
|
+
: _j.map((m) =>
|
|
198
|
+
m === null || m === void 0 ? void 0 : m.toString()
|
|
199
|
+
)) || [],
|
|
200
|
+
(body === null || body === void 0 ? void 0 : body.measureunits) ||
|
|
201
|
+
[]
|
|
202
|
+
)) === null || _k === void 0
|
|
203
|
+
? void 0
|
|
204
|
+
: _k.length)
|
|
205
|
+
) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
// Update
|
|
209
|
+
try {
|
|
210
|
+
const updated_UoM = await repzo.measureunitFamily.update(
|
|
211
|
+
repzo_family._id,
|
|
212
|
+
body
|
|
213
|
+
);
|
|
214
|
+
result.updated++;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.log(
|
|
217
|
+
"Update Measure Unit Family Failed >> ",
|
|
218
|
+
(_l = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
219
|
+
_l === void 0
|
|
220
|
+
? void 0
|
|
221
|
+
: _l.data,
|
|
222
|
+
body
|
|
223
|
+
);
|
|
224
|
+
failed_docs_report.push({
|
|
225
|
+
method: "update",
|
|
226
|
+
doc_id:
|
|
227
|
+
repzo_family === null || repzo_family === void 0
|
|
228
|
+
? void 0
|
|
229
|
+
: repzo_family._id,
|
|
230
|
+
doc: body,
|
|
231
|
+
error_message: set_error(e),
|
|
232
|
+
});
|
|
233
|
+
result.failed++;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// console.log(result);
|
|
238
|
+
await update_bench_time(
|
|
239
|
+
repzo,
|
|
240
|
+
commandEvent.app._id,
|
|
241
|
+
bench_time_key,
|
|
242
|
+
new_bench_time
|
|
243
|
+
);
|
|
244
|
+
await commandLog
|
|
245
|
+
.setStatus(
|
|
246
|
+
"success",
|
|
247
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
248
|
+
)
|
|
249
|
+
.setBody(result)
|
|
250
|
+
.commit();
|
|
251
|
+
return result;
|
|
252
|
+
} catch (e) {
|
|
253
|
+
//@ts-ignore
|
|
254
|
+
console.error(
|
|
255
|
+
((_m = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
256
|
+
_m === void 0
|
|
257
|
+
? void 0
|
|
258
|
+
: _m.data) || e
|
|
259
|
+
);
|
|
260
|
+
await commandLog.setStatus("fail", e).commit();
|
|
261
|
+
throw e;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import Repzo from "repzo";
|
|
2
|
+
import {
|
|
3
|
+
_create,
|
|
4
|
+
update_bench_time,
|
|
5
|
+
date_formatting,
|
|
6
|
+
set_error,
|
|
7
|
+
} from "../util.js";
|
|
8
|
+
export const sync_payment_term = async (commandEvent) => {
|
|
9
|
+
var _a, _b, _c, _d, _e;
|
|
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,
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
const commandLog = new Repzo.CommandLog(
|
|
19
|
+
repzo,
|
|
20
|
+
commandEvent.app,
|
|
21
|
+
commandEvent.command
|
|
22
|
+
);
|
|
23
|
+
try {
|
|
24
|
+
console.log("sync_payment_term");
|
|
25
|
+
const new_bench_time = new Date().toISOString();
|
|
26
|
+
const bench_time_key = "bench_time_payment_term";
|
|
27
|
+
await commandLog.load(commandEvent.sync_id);
|
|
28
|
+
await commandLog
|
|
29
|
+
.addDetail("Repzo SAP: Started Syncing Payments Term")
|
|
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_clients = await get_sap_clients(
|
|
41
|
+
commandEvent.app.formData.sapHostUrl,
|
|
42
|
+
{
|
|
43
|
+
updateAt: commandEvent.app.options_formData[bench_time_key],
|
|
44
|
+
GroupCode: commandEvent.app.formData.GroupCode,
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
const sap_unique_payment_terms = {};
|
|
48
|
+
sap_clients === null || sap_clients === void 0
|
|
49
|
+
? void 0
|
|
50
|
+
: sap_clients.forEach((client) => {
|
|
51
|
+
const paymentTerm = client.PAYMENTTERM;
|
|
52
|
+
sap_unique_payment_terms[paymentTerm] = true;
|
|
53
|
+
});
|
|
54
|
+
const sap_payment_terms = Object.keys(sap_unique_payment_terms);
|
|
55
|
+
result.sap_total =
|
|
56
|
+
sap_payment_terms === null || sap_payment_terms === void 0
|
|
57
|
+
? void 0
|
|
58
|
+
: sap_payment_terms.length;
|
|
59
|
+
await commandLog
|
|
60
|
+
.addDetail(
|
|
61
|
+
`${result.sap_total} Payments Term in SAP changed since ${
|
|
62
|
+
commandEvent.app.options_formData[bench_time_key] || "ever"
|
|
63
|
+
}`
|
|
64
|
+
)
|
|
65
|
+
.commit();
|
|
66
|
+
const repzo_payment_terms = await repzo.paymentTerm.find({
|
|
67
|
+
per_page: 50000,
|
|
68
|
+
});
|
|
69
|
+
result.repzo_total =
|
|
70
|
+
(_b =
|
|
71
|
+
repzo_payment_terms === null || repzo_payment_terms === void 0
|
|
72
|
+
? void 0
|
|
73
|
+
: repzo_payment_terms.data) === null || _b === void 0
|
|
74
|
+
? void 0
|
|
75
|
+
: _b.length;
|
|
76
|
+
await commandLog
|
|
77
|
+
.addDetail(
|
|
78
|
+
`${
|
|
79
|
+
(_c =
|
|
80
|
+
repzo_payment_terms === null || repzo_payment_terms === void 0
|
|
81
|
+
? void 0
|
|
82
|
+
: repzo_payment_terms.data) === null || _c === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _c.length
|
|
85
|
+
} Payments Term in Repzo`
|
|
86
|
+
)
|
|
87
|
+
.commit();
|
|
88
|
+
for (
|
|
89
|
+
let i = 0;
|
|
90
|
+
i <
|
|
91
|
+
(sap_payment_terms === null || sap_payment_terms === void 0
|
|
92
|
+
? void 0
|
|
93
|
+
: sap_payment_terms.length);
|
|
94
|
+
i++
|
|
95
|
+
) {
|
|
96
|
+
const sap_payment_term = sap_payment_terms[i];
|
|
97
|
+
const repzo_payment_term = repzo_payment_terms.data.find(
|
|
98
|
+
(r_payment_term) => {
|
|
99
|
+
var _a;
|
|
100
|
+
return (
|
|
101
|
+
((_a = r_payment_term.integration_meta) === null || _a === void 0
|
|
102
|
+
? void 0
|
|
103
|
+
: _a.id) == `${nameSpace}_${sap_payment_term}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
const body = {
|
|
108
|
+
name: sap_payment_term.toString(),
|
|
109
|
+
due_days: Number(sap_payment_term),
|
|
110
|
+
integration_meta: {
|
|
111
|
+
id: `${nameSpace}_${sap_payment_term}`,
|
|
112
|
+
},
|
|
113
|
+
company_namespace: [nameSpace],
|
|
114
|
+
};
|
|
115
|
+
if (!repzo_payment_term) {
|
|
116
|
+
// Create
|
|
117
|
+
try {
|
|
118
|
+
const created_payment_term = await repzo.paymentTerm.create(body);
|
|
119
|
+
result.created++;
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.log(
|
|
122
|
+
"Create Payment Term Failed >> ",
|
|
123
|
+
e === null || e === void 0 ? void 0 : e.response,
|
|
124
|
+
body
|
|
125
|
+
);
|
|
126
|
+
failed_docs_report.push({
|
|
127
|
+
method: "create",
|
|
128
|
+
doc: body,
|
|
129
|
+
error_message: set_error(e),
|
|
130
|
+
});
|
|
131
|
+
result.failed++;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
if (
|
|
135
|
+
(repzo_payment_term === null || repzo_payment_term === void 0
|
|
136
|
+
? void 0
|
|
137
|
+
: repzo_payment_term.name) ==
|
|
138
|
+
(body === null || body === void 0 ? void 0 : body.name) &&
|
|
139
|
+
(repzo_payment_term === null || repzo_payment_term === void 0
|
|
140
|
+
? void 0
|
|
141
|
+
: repzo_payment_term.due_days) ==
|
|
142
|
+
(body === null || body === void 0 ? void 0 : body.due_days)
|
|
143
|
+
)
|
|
144
|
+
continue;
|
|
145
|
+
// Update
|
|
146
|
+
try {
|
|
147
|
+
const updated_payment_term = await repzo.paymentTerm.update(
|
|
148
|
+
repzo_payment_term._id,
|
|
149
|
+
body
|
|
150
|
+
);
|
|
151
|
+
result.updated++;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.log(
|
|
154
|
+
"Update Payment Term Failed >> ",
|
|
155
|
+
(_d = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
156
|
+
_d === void 0
|
|
157
|
+
? void 0
|
|
158
|
+
: _d.data,
|
|
159
|
+
body
|
|
160
|
+
);
|
|
161
|
+
failed_docs_report.push({
|
|
162
|
+
method: "update",
|
|
163
|
+
doc_id:
|
|
164
|
+
repzo_payment_term === null || repzo_payment_term === void 0
|
|
165
|
+
? void 0
|
|
166
|
+
: repzo_payment_term._id,
|
|
167
|
+
doc: body,
|
|
168
|
+
error_message: set_error(e),
|
|
169
|
+
});
|
|
170
|
+
result.failed++;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// console.log(result);
|
|
175
|
+
await update_bench_time(
|
|
176
|
+
repzo,
|
|
177
|
+
commandEvent.app._id,
|
|
178
|
+
bench_time_key,
|
|
179
|
+
new_bench_time
|
|
180
|
+
);
|
|
181
|
+
await commandLog
|
|
182
|
+
.setStatus(
|
|
183
|
+
"success",
|
|
184
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
185
|
+
)
|
|
186
|
+
.setBody(result)
|
|
187
|
+
.commit();
|
|
188
|
+
return result;
|
|
189
|
+
} catch (e) {
|
|
190
|
+
//@ts-ignore
|
|
191
|
+
console.error(
|
|
192
|
+
((_e = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
193
|
+
_e === void 0
|
|
194
|
+
? void 0
|
|
195
|
+
: _e.data) || e
|
|
196
|
+
);
|
|
197
|
+
await commandLog.setStatus("fail", e).commit();
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
202
|
+
try {
|
|
203
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
204
|
+
Active: "Y",
|
|
205
|
+
Frozen: "N",
|
|
206
|
+
UpdateAt: date_formatting(
|
|
207
|
+
query === null || query === void 0 ? void 0 : query.updateAt,
|
|
208
|
+
"YYYYMMDD:HHmmss"
|
|
209
|
+
),
|
|
210
|
+
GroupCode:
|
|
211
|
+
(query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
212
|
+
});
|
|
213
|
+
return sap_clients.Customers;
|
|
214
|
+
} catch (e) {
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CommandEvent } from "../types";
|
|
2
|
+
export declare const sync_price_list: (commandEvent: CommandEvent) => Promise<{
|
|
3
|
+
PL: {
|
|
4
|
+
created: number;
|
|
5
|
+
updated: number;
|
|
6
|
+
failed: number;
|
|
7
|
+
};
|
|
8
|
+
PL_items: {
|
|
9
|
+
created: number;
|
|
10
|
+
updated: number;
|
|
11
|
+
failed: number;
|
|
12
|
+
};
|
|
13
|
+
sap_total: number;
|
|
14
|
+
repzo_total: number;
|
|
15
|
+
repzo_PL_items: number;
|
|
16
|
+
sap_UoMs_total: number;
|
|
17
|
+
repzo_products_total: number;
|
|
18
|
+
}>;
|