repzo-sap-absjo 1.0.9 → 1.0.10
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/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +206 -363
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +117 -200
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +155 -290
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +169 -321
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +136 -220
- 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 +326 -612
- 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 +334 -337
- 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_transfer.ts +2 -2
|
@@ -1,217 +1,129 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
2
|
import DataSet from "data-set-query";
|
|
3
|
-
import {
|
|
4
|
-
_create,
|
|
5
|
-
update_bench_time,
|
|
6
|
-
date_formatting,
|
|
7
|
-
set_error,
|
|
8
|
-
} from "../util.js";
|
|
3
|
+
import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
|
|
9
4
|
export const sync_warehouse = async (commandEvent) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
? void 0
|
|
14
|
-
: _a.repzoApiKey,
|
|
15
|
-
{
|
|
16
|
-
env: commandEvent.env,
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
const commandLog = new Repzo.CommandLog(
|
|
20
|
-
repzo,
|
|
21
|
-
commandEvent.app,
|
|
22
|
-
commandEvent.command
|
|
23
|
-
);
|
|
24
|
-
try {
|
|
25
|
-
// console.log("sync_warehouse");
|
|
26
|
-
const new_bench_time = new Date().toISOString();
|
|
27
|
-
const bench_time_key = "bench_time_warehouse";
|
|
28
|
-
await commandLog.load(commandEvent.sync_id);
|
|
29
|
-
await commandLog
|
|
30
|
-
.addDetail("Repzo SAP: Started Syncing Warehouses")
|
|
31
|
-
.commit();
|
|
32
|
-
const nameSpace = commandEvent.nameSpace.join("_");
|
|
33
|
-
const result = {
|
|
34
|
-
sap_total: 0,
|
|
35
|
-
repzo_total: 0,
|
|
36
|
-
created: 0,
|
|
37
|
-
updated: 0,
|
|
38
|
-
failed: 0,
|
|
39
|
-
};
|
|
40
|
-
const failed_docs_report = [];
|
|
41
|
-
const sap_warehouses = await get_sap_warehouses(
|
|
42
|
-
commandEvent.app.formData.sapHostUrl,
|
|
43
|
-
{
|
|
44
|
-
updateAt:
|
|
45
|
-
commandEvent.app.formData.warehouseDefaultUpdateDate ||
|
|
46
|
-
commandEvent.app.options_formData[bench_time_key],
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
result.sap_total =
|
|
50
|
-
(_b =
|
|
51
|
-
sap_warehouses === null || sap_warehouses === void 0
|
|
52
|
-
? void 0
|
|
53
|
-
: sap_warehouses.Warehouses) === null || _b === void 0
|
|
54
|
-
? void 0
|
|
55
|
-
: _b.length;
|
|
56
|
-
await commandLog
|
|
57
|
-
.addDetail(
|
|
58
|
-
`${
|
|
59
|
-
(_c =
|
|
60
|
-
sap_warehouses === null || sap_warehouses === void 0
|
|
61
|
-
? void 0
|
|
62
|
-
: sap_warehouses.Warehouses) === null || _c === void 0
|
|
63
|
-
? void 0
|
|
64
|
-
: _c.length
|
|
65
|
-
} warehouses changed since ${
|
|
66
|
-
commandEvent.app.formData.warehouseDefaultUpdateDate ||
|
|
67
|
-
commandEvent.app.options_formData[bench_time_key] ||
|
|
68
|
-
"ever"
|
|
69
|
-
}`
|
|
70
|
-
)
|
|
71
|
-
.commit();
|
|
72
|
-
const db = new DataSet([], { autoIndex: false });
|
|
73
|
-
db.createIndex({
|
|
74
|
-
WAREHOUSECODE: true,
|
|
75
|
-
WAREHOUSENAME: 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,
|
|
76
8
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
: _e.length
|
|
99
|
-
} warehouses in Repzo`
|
|
100
|
-
)
|
|
101
|
-
.commit();
|
|
102
|
-
for (
|
|
103
|
-
let i = 0;
|
|
104
|
-
i <
|
|
105
|
-
((_f =
|
|
106
|
-
sap_warehouses === null || sap_warehouses === void 0
|
|
107
|
-
? void 0
|
|
108
|
-
: sap_warehouses.Warehouses) === null || _f === void 0
|
|
109
|
-
? void 0
|
|
110
|
-
: _f.length);
|
|
111
|
-
i++
|
|
112
|
-
) {
|
|
113
|
-
const sap_warehouse = sap_warehouses.Warehouses[i];
|
|
114
|
-
const repzo_warehouse = repzo_warehouses.data.find(
|
|
115
|
-
(r_warehouse) =>
|
|
116
|
-
r_warehouse.code == sap_warehouse.WAREHOUSECODE ||
|
|
117
|
-
r_warehouse.name == sap_warehouse.WAREHOUSENAME
|
|
118
|
-
);
|
|
119
|
-
const body = {
|
|
120
|
-
_id:
|
|
121
|
-
repzo_warehouse === null || repzo_warehouse === void 0
|
|
122
|
-
? void 0
|
|
123
|
-
: repzo_warehouse._id,
|
|
124
|
-
name: sap_warehouse.WAREHOUSENAME,
|
|
125
|
-
code: sap_warehouse.WAREHOUSECODE,
|
|
126
|
-
type:
|
|
127
|
-
sap_warehouse.WAREHOUSECODE.indexOf("VS") == 0 ||
|
|
128
|
-
sap_warehouse.WAREHOUSECODE.indexOf("COOPS1") == 0
|
|
129
|
-
? "van"
|
|
130
|
-
: "main",
|
|
131
|
-
disabled: sap_warehouse.INACTIVE == "N" ? false : true,
|
|
132
|
-
};
|
|
133
|
-
if (!repzo_warehouse) {
|
|
134
|
-
// Create
|
|
135
|
-
try {
|
|
136
|
-
const created_warehouse = await repzo.warehouse.create(body);
|
|
137
|
-
result.created++;
|
|
138
|
-
} catch (e) {
|
|
139
|
-
// console.log("Create warehouse Failed >> ", e?.response, body);
|
|
140
|
-
failed_docs_report.push({
|
|
141
|
-
method: "create",
|
|
142
|
-
doc: body,
|
|
143
|
-
error_message: set_error(e),
|
|
144
|
-
});
|
|
145
|
-
result.failed++;
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
const found_identical_docs = db.search({
|
|
149
|
-
WAREHOUSECODE: repzo_warehouse.code,
|
|
150
|
-
WAREHOUSENAME: repzo_warehouse.name,
|
|
9
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
10
|
+
try {
|
|
11
|
+
// console.log("sync_warehouse");
|
|
12
|
+
const new_bench_time = new Date().toISOString();
|
|
13
|
+
const bench_time_key = "bench_time_warehouse";
|
|
14
|
+
await commandLog.load(commandEvent.sync_id);
|
|
15
|
+
await commandLog
|
|
16
|
+
.addDetail("Repzo SAP: Started Syncing Warehouses")
|
|
17
|
+
.commit();
|
|
18
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
19
|
+
const result = {
|
|
20
|
+
sap_total: 0,
|
|
21
|
+
repzo_total: 0,
|
|
22
|
+
created: 0,
|
|
23
|
+
updated: 0,
|
|
24
|
+
failed: 0,
|
|
25
|
+
};
|
|
26
|
+
const failed_docs_report = [];
|
|
27
|
+
const sap_warehouses = await get_sap_warehouses(commandEvent.app.formData.sapHostUrl, {
|
|
28
|
+
updateAt: commandEvent.app.formData.warehouseDefaultUpdateDate ||
|
|
29
|
+
commandEvent.app.options_formData[bench_time_key],
|
|
151
30
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
31
|
+
result.sap_total = (_b = sap_warehouses === null || sap_warehouses === void 0 ? void 0 : sap_warehouses.Warehouses) === null || _b === void 0 ? void 0 : _b.length;
|
|
32
|
+
await commandLog
|
|
33
|
+
.addDetail(`${(_c = sap_warehouses === null || sap_warehouses === void 0 ? void 0 : sap_warehouses.Warehouses) === null || _c === void 0 ? void 0 : _c.length} warehouses changed since ${commandEvent.app.formData.warehouseDefaultUpdateDate ||
|
|
34
|
+
commandEvent.app.options_formData[bench_time_key] ||
|
|
35
|
+
"ever"}`)
|
|
36
|
+
.commit();
|
|
37
|
+
const db = new DataSet([], { autoIndex: false });
|
|
38
|
+
db.createIndex({
|
|
39
|
+
WAREHOUSECODE: true,
|
|
40
|
+
WAREHOUSENAME: true,
|
|
41
|
+
});
|
|
42
|
+
db.load(sap_warehouses === null || sap_warehouses === void 0 ? void 0 : sap_warehouses.Warehouses);
|
|
43
|
+
const repzo_warehouses = await repzo.warehouse.find({ per_page: 50000 });
|
|
44
|
+
result.repzo_total = (_d = repzo_warehouses === null || repzo_warehouses === void 0 ? void 0 : repzo_warehouses.data) === null || _d === void 0 ? void 0 : _d.length;
|
|
45
|
+
await commandLog
|
|
46
|
+
.addDetail(`${(_e = repzo_warehouses === null || repzo_warehouses === void 0 ? void 0 : repzo_warehouses.data) === null || _e === void 0 ? void 0 : _e.length} warehouses in Repzo`)
|
|
47
|
+
.commit();
|
|
48
|
+
for (let i = 0; i < ((_f = sap_warehouses === null || sap_warehouses === void 0 ? void 0 : sap_warehouses.Warehouses) === null || _f === void 0 ? void 0 : _f.length); i++) {
|
|
49
|
+
const sap_warehouse = sap_warehouses.Warehouses[i];
|
|
50
|
+
const repzo_warehouse = repzo_warehouses.data.find((r_warehouse) => r_warehouse.code == sap_warehouse.WAREHOUSECODE ||
|
|
51
|
+
r_warehouse.name == sap_warehouse.WAREHOUSENAME);
|
|
52
|
+
const body = {
|
|
53
|
+
_id: repzo_warehouse === null || repzo_warehouse === void 0 ? void 0 : repzo_warehouse._id,
|
|
54
|
+
name: sap_warehouse.WAREHOUSENAME,
|
|
55
|
+
code: sap_warehouse.WAREHOUSECODE,
|
|
56
|
+
type: sap_warehouse.WAREHOUSECODE.indexOf("VS") == 0 ||
|
|
57
|
+
sap_warehouse.WAREHOUSECODE.indexOf("COOPS1") == 0
|
|
58
|
+
? "van"
|
|
59
|
+
: "main",
|
|
60
|
+
disabled: sap_warehouse.INACTIVE == "N" ? false : true,
|
|
61
|
+
};
|
|
62
|
+
if (!repzo_warehouse) {
|
|
63
|
+
// Create
|
|
64
|
+
try {
|
|
65
|
+
const created_warehouse = await repzo.warehouse.create(body);
|
|
66
|
+
result.created++;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// console.log("Create warehouse Failed >> ", e?.response, body);
|
|
70
|
+
failed_docs_report.push({
|
|
71
|
+
method: "create",
|
|
72
|
+
doc: body,
|
|
73
|
+
error_message: set_error(e),
|
|
74
|
+
});
|
|
75
|
+
result.failed++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const found_identical_docs = db.search({
|
|
80
|
+
WAREHOUSECODE: repzo_warehouse.code,
|
|
81
|
+
WAREHOUSENAME: repzo_warehouse.name,
|
|
82
|
+
});
|
|
83
|
+
if (found_identical_docs.length)
|
|
84
|
+
continue; // Nothing has changed so no need for updates
|
|
85
|
+
// Update
|
|
86
|
+
try {
|
|
87
|
+
const updated_warehouse = await repzo.warehouse.update(repzo_warehouse._id, body);
|
|
88
|
+
result.updated++;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
// console.log("Update warehouse Failed >> ", e, body);
|
|
92
|
+
failed_docs_report.push({
|
|
93
|
+
method: "update",
|
|
94
|
+
doc_id: repzo_warehouse === null || repzo_warehouse === void 0 ? void 0 : repzo_warehouse._id,
|
|
95
|
+
doc: body,
|
|
96
|
+
error_message: set_error(e),
|
|
97
|
+
});
|
|
98
|
+
result.failed++;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
172
101
|
}
|
|
173
|
-
|
|
102
|
+
// console.log(result);
|
|
103
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time, "YYYY-MM-DD");
|
|
104
|
+
await commandLog
|
|
105
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
106
|
+
.setBody(result)
|
|
107
|
+
.commit();
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
//@ts-ignore
|
|
112
|
+
console.error(((_g = e === null || e === void 0 ? void 0 : e.response) === null || _g === void 0 ? void 0 : _g.data) || e);
|
|
113
|
+
await commandLog.setStatus("fail", e).commit();
|
|
114
|
+
throw e === null || e === void 0 ? void 0 : e.response;
|
|
174
115
|
}
|
|
175
|
-
// console.log(result);
|
|
176
|
-
await update_bench_time(
|
|
177
|
-
repzo,
|
|
178
|
-
commandEvent.app._id,
|
|
179
|
-
bench_time_key,
|
|
180
|
-
new_bench_time,
|
|
181
|
-
"YYYY-MM-DD"
|
|
182
|
-
);
|
|
183
|
-
await commandLog
|
|
184
|
-
.setStatus(
|
|
185
|
-
"success",
|
|
186
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
187
|
-
)
|
|
188
|
-
.setBody(result)
|
|
189
|
-
.commit();
|
|
190
|
-
return result;
|
|
191
|
-
} catch (e) {
|
|
192
|
-
//@ts-ignore
|
|
193
|
-
console.error(
|
|
194
|
-
((_g = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
195
|
-
_g === void 0
|
|
196
|
-
? void 0
|
|
197
|
-
: _g.data) || e
|
|
198
|
-
);
|
|
199
|
-
await commandLog.setStatus("fail", e).commit();
|
|
200
|
-
throw e === null || e === void 0 ? void 0 : e.response;
|
|
201
|
-
}
|
|
202
116
|
};
|
|
203
117
|
const get_sap_warehouses = async (serviceEndPoint, query) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
throw e;
|
|
216
|
-
}
|
|
118
|
+
try {
|
|
119
|
+
const sap_warehouses = await _create(serviceEndPoint, "/Warehouses", {
|
|
120
|
+
UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD"),
|
|
121
|
+
Inactive: "N",
|
|
122
|
+
Locked: "N",
|
|
123
|
+
});
|
|
124
|
+
return sap_warehouses;
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
throw e;
|
|
128
|
+
}
|
|
217
129
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
export declare const Actions: (
|
|
2
|
-
event: any,
|
|
3
|
-
options: import("./types.js").Config
|
|
4
|
-
) => Promise<any>;
|
|
1
|
+
export declare const Actions: (event: any, options: import("./types.js").Config) => Promise<any>;
|
|
5
2
|
export declare const ActionsList: import("./types.js").Action[];
|
|
6
|
-
export declare const Commands: (
|
|
7
|
-
|
|
8
|
-
) => Promise<
|
|
9
|
-
| void
|
|
10
|
-
| import("./types.js").Result
|
|
11
|
-
| {
|
|
12
|
-
PL: {
|
|
3
|
+
export declare const Commands: (CommandEvent: import("./types.js").CommandEvent) => Promise<void | import("./types.js").Result | {
|
|
4
|
+
PL: {
|
|
13
5
|
created: number;
|
|
14
6
|
updated: number;
|
|
15
7
|
failed: number;
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
};
|
|
9
|
+
PL_items: {
|
|
18
10
|
created: number;
|
|
19
11
|
updated: number;
|
|
20
12
|
failed: number;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
>;
|
|
13
|
+
};
|
|
14
|
+
sap_total: number;
|
|
15
|
+
repzo_total: number;
|
|
16
|
+
repzo_PL_items: number;
|
|
17
|
+
sap_UoMs_total: number;
|
|
18
|
+
repzo_products_total: number;
|
|
19
|
+
}>;
|
|
29
20
|
export declare const CommandsList: import("./types.js").Command[];
|