repzo-sap-absjo 1.0.18 → 1.0.20
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 +207 -365
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +107 -195
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +146 -285
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +158 -312
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +126 -223
- 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 +48 -67
- package/lib/commands/brand.d.ts +1 -3
- package/lib/commands/brand.js +100 -174
- 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 +62 -62
- 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 +263 -485
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -160
- 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/brand.js +90 -90
- 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 +53 -77
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
package/lib/commands/channel.js
CHANGED
|
@@ -1,206 +1,125 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import {
|
|
3
|
-
_create,
|
|
4
|
-
update_bench_time,
|
|
5
|
-
date_formatting,
|
|
6
|
-
set_error,
|
|
7
|
-
} from "../util.js";
|
|
2
|
+
import { _create, update_bench_time, date_formatting, set_error, } from "../util.js";
|
|
8
3
|
export const sync_channel = async (commandEvent) => {
|
|
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
|
-
|
|
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_channels = {};
|
|
48
|
-
sap_clients === null || sap_clients === void 0
|
|
49
|
-
? void 0
|
|
50
|
-
: sap_clients.forEach((client) => {
|
|
51
|
-
const channel = client.CLIENTGROUP;
|
|
52
|
-
sap_unique_channels[channel] = true;
|
|
4
|
+
var _a, _b, _c, _d;
|
|
5
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
6
|
+
env: commandEvent.env,
|
|
7
|
+
});
|
|
8
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
9
|
+
try {
|
|
10
|
+
// console.log("sync_channel");
|
|
11
|
+
const new_bench_time = new Date().toISOString();
|
|
12
|
+
const bench_time_key = "bench_time_channel";
|
|
13
|
+
await commandLog.load(commandEvent.sync_id);
|
|
14
|
+
await commandLog
|
|
15
|
+
.addDetail("Repzo SAP: Started Syncing Client Channels")
|
|
16
|
+
.commit();
|
|
17
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
18
|
+
const result = {
|
|
19
|
+
sap_total: 0,
|
|
20
|
+
repzo_total: 0,
|
|
21
|
+
created: 0,
|
|
22
|
+
updated: 0,
|
|
23
|
+
failed: 0,
|
|
24
|
+
};
|
|
25
|
+
const failed_docs_report = [];
|
|
26
|
+
const sap_clients = await get_sap_clients(commandEvent.app.formData.sapHostUrl, {
|
|
27
|
+
updateAt: commandEvent.app.options_formData[bench_time_key],
|
|
28
|
+
GroupCode: commandEvent.app.formData.GroupCode,
|
|
53
29
|
});
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
doc: body,
|
|
121
|
-
error_message: set_error(e),
|
|
122
|
-
});
|
|
123
|
-
result.failed++;
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
if (
|
|
127
|
-
(repzo_channel === null || repzo_channel === void 0
|
|
128
|
-
? void 0
|
|
129
|
-
: repzo_channel.name) ==
|
|
130
|
-
(body === null || body === void 0 ? void 0 : body.name) &&
|
|
131
|
-
(repzo_channel === null || repzo_channel === void 0
|
|
132
|
-
? void 0
|
|
133
|
-
: repzo_channel.disabled) ==
|
|
134
|
-
(body === null || body === void 0 ? void 0 : body.disabled)
|
|
135
|
-
)
|
|
136
|
-
continue;
|
|
137
|
-
// Update
|
|
138
|
-
try {
|
|
139
|
-
const updated_channel = await repzo.channel.update(
|
|
140
|
-
repzo_channel._id,
|
|
141
|
-
body
|
|
142
|
-
);
|
|
143
|
-
result.updated++;
|
|
144
|
-
} catch (e) {
|
|
145
|
-
// console.log(
|
|
146
|
-
// "Update Client Channel Failed >> ",
|
|
147
|
-
// e?.response?.data,
|
|
148
|
-
// body
|
|
149
|
-
// );
|
|
150
|
-
failed_docs_report.push({
|
|
151
|
-
method: "update",
|
|
152
|
-
doc_id:
|
|
153
|
-
repzo_channel === null || repzo_channel === void 0
|
|
154
|
-
? void 0
|
|
155
|
-
: repzo_channel._id,
|
|
156
|
-
doc: body,
|
|
157
|
-
error_message: set_error(e),
|
|
158
|
-
});
|
|
159
|
-
result.failed++;
|
|
30
|
+
const sap_unique_channels = {};
|
|
31
|
+
sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.forEach((client) => {
|
|
32
|
+
const channel = client.CLIENTGROUP;
|
|
33
|
+
sap_unique_channels[channel] = true;
|
|
34
|
+
});
|
|
35
|
+
const sap_channels = Object.keys(sap_unique_channels);
|
|
36
|
+
result.sap_total = sap_channels === null || sap_channels === void 0 ? void 0 : sap_channels.length;
|
|
37
|
+
await commandLog
|
|
38
|
+
.addDetail(`${result.sap_total} Client Channels in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
|
|
39
|
+
.commit();
|
|
40
|
+
const repzo_channels = await repzo.channel.find({ per_page: 50000 });
|
|
41
|
+
result.repzo_total = (_b = repzo_channels === null || repzo_channels === void 0 ? void 0 : repzo_channels.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
42
|
+
await commandLog
|
|
43
|
+
.addDetail(`${(_c = repzo_channels === null || repzo_channels === void 0 ? void 0 : repzo_channels.data) === null || _c === void 0 ? void 0 : _c.length} Client Channels in Repzo`)
|
|
44
|
+
.commit();
|
|
45
|
+
for (let i = 0; i < (sap_channels === null || sap_channels === void 0 ? void 0 : sap_channels.length); i++) {
|
|
46
|
+
const sap_channel = sap_channels[i];
|
|
47
|
+
const repzo_channel = repzo_channels.data.find((r_channel) => { var _a; return ((_a = r_channel.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${sap_channel}`; });
|
|
48
|
+
const body = {
|
|
49
|
+
name: sap_channel,
|
|
50
|
+
disabled: false,
|
|
51
|
+
integration_meta: {
|
|
52
|
+
id: `${nameSpace}_${sap_channel}`,
|
|
53
|
+
},
|
|
54
|
+
company_namespace: [nameSpace],
|
|
55
|
+
};
|
|
56
|
+
if (!repzo_channel) {
|
|
57
|
+
// Create
|
|
58
|
+
try {
|
|
59
|
+
const created_channel = await repzo.channel.create(body);
|
|
60
|
+
result.created++;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
// console.log("Create Client Channel Failed >> ", e?.response, body);
|
|
64
|
+
failed_docs_report.push({
|
|
65
|
+
method: "create",
|
|
66
|
+
doc: body,
|
|
67
|
+
error_message: set_error(e),
|
|
68
|
+
});
|
|
69
|
+
result.failed++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if ((repzo_channel === null || repzo_channel === void 0 ? void 0 : repzo_channel.name) == (body === null || body === void 0 ? void 0 : body.name) &&
|
|
74
|
+
(repzo_channel === null || repzo_channel === void 0 ? void 0 : repzo_channel.disabled) == (body === null || body === void 0 ? void 0 : body.disabled))
|
|
75
|
+
continue;
|
|
76
|
+
// Update
|
|
77
|
+
try {
|
|
78
|
+
const updated_channel = await repzo.channel.update(repzo_channel._id, body);
|
|
79
|
+
result.updated++;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
// console.log(
|
|
83
|
+
// "Update Client Channel Failed >> ",
|
|
84
|
+
// e?.response?.data,
|
|
85
|
+
// body
|
|
86
|
+
// );
|
|
87
|
+
failed_docs_report.push({
|
|
88
|
+
method: "update",
|
|
89
|
+
doc_id: repzo_channel === null || repzo_channel === void 0 ? void 0 : repzo_channel._id,
|
|
90
|
+
doc: body,
|
|
91
|
+
error_message: set_error(e),
|
|
92
|
+
});
|
|
93
|
+
result.failed++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
160
96
|
}
|
|
161
|
-
|
|
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(((_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) || e);
|
|
108
|
+
await commandLog.setStatus("fail", e).commit();
|
|
109
|
+
throw e;
|
|
162
110
|
}
|
|
163
|
-
// console.log(result);
|
|
164
|
-
await update_bench_time(
|
|
165
|
-
repzo,
|
|
166
|
-
commandEvent.app._id,
|
|
167
|
-
bench_time_key,
|
|
168
|
-
new_bench_time
|
|
169
|
-
);
|
|
170
|
-
await commandLog
|
|
171
|
-
.setStatus(
|
|
172
|
-
"success",
|
|
173
|
-
failed_docs_report.length ? failed_docs_report : null
|
|
174
|
-
)
|
|
175
|
-
.setBody(result)
|
|
176
|
-
.commit();
|
|
177
|
-
return result;
|
|
178
|
-
} catch (e) {
|
|
179
|
-
//@ts-ignore
|
|
180
|
-
console.error(
|
|
181
|
-
((_d = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
182
|
-
_d === void 0
|
|
183
|
-
? void 0
|
|
184
|
-
: _d.data) || e
|
|
185
|
-
);
|
|
186
|
-
await commandLog.setStatus("fail", e).commit();
|
|
187
|
-
throw e;
|
|
188
|
-
}
|
|
189
111
|
};
|
|
190
112
|
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
} catch (e) {
|
|
204
|
-
throw e;
|
|
205
|
-
}
|
|
113
|
+
try {
|
|
114
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
115
|
+
Active: "Y",
|
|
116
|
+
Frozen: "N",
|
|
117
|
+
UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
|
|
118
|
+
GroupCode: (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
119
|
+
});
|
|
120
|
+
return sap_clients.Customers;
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
throw e;
|
|
124
|
+
}
|
|
206
125
|
};
|
package/lib/commands/client.d.ts
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
import { CommandEvent, Result } from "../types";
|
|
2
2
|
export interface SAPClient {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
3
|
+
CLIENTID: string;
|
|
4
|
+
CLIENTDESC: string;
|
|
5
|
+
CLIENTADDRESS?: string;
|
|
6
|
+
CLIENTCITY?: string;
|
|
7
|
+
CLIENTCOUNTRY?: string;
|
|
8
|
+
CLIENTCOUNTY?: string;
|
|
9
|
+
CLIENTGROUPCODE: number;
|
|
10
|
+
CLIENTGROUP: string;
|
|
11
|
+
PAYMENTTERM: number;
|
|
12
|
+
CLIENTCONTACTPERSON?: string;
|
|
13
|
+
CLIENTPHONE1?: string;
|
|
14
|
+
CLIENTPHONE2?: string;
|
|
15
|
+
CLIENTNOTE?: string;
|
|
16
|
+
CLIENTSTATUS: "N" | "Y";
|
|
17
|
+
CLIENTCREDITCONSUMED: number;
|
|
18
|
+
CLIENTMAXCHEQUEVALUE: number;
|
|
19
|
+
CLIENTCREDITLIMIT: number;
|
|
20
|
+
CLIENTPRICELISTID: number;
|
|
21
|
+
CLIENTADDRESSID?: string;
|
|
22
|
+
CLIENTDESCF?: string;
|
|
23
|
+
SALESPERSONCODE: number;
|
|
24
|
+
DISCOUNTPERCENT: number;
|
|
25
|
+
ACTIVE: "N" | "Y";
|
|
26
|
+
FROZEN: "N" | "Y";
|
|
27
|
+
TERRITORYID?: string;
|
|
28
|
+
TERRITORYNAME?: string;
|
|
29
|
+
CREATEDATE: string;
|
|
30
|
+
UPDATEDATE: string;
|
|
31
|
+
PARENTCODE?: string;
|
|
32
32
|
}
|
|
33
33
|
export interface SAPClients {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
result: "Success";
|
|
35
|
+
Customers: SAPClient[];
|
|
36
36
|
}
|
|
37
|
-
export declare const sync_client: (
|
|
38
|
-
commandEvent: CommandEvent
|
|
39
|
-
) => Promise<Result>;
|
|
37
|
+
export declare const sync_client: (commandEvent: CommandEvent) => Promise<Result>;
|