repzo-sap-absjo 1.0.20 → 1.0.22
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 +1 -0
- package/lib/actions/create_invoice.d.ts +19 -13
- package/lib/actions/create_invoice.js +359 -210
- package/lib/actions/create_payment.d.ts +4 -1
- package/lib/actions/create_payment.js +195 -107
- package/lib/actions/create_proforma.d.ts +4 -1
- package/lib/actions/create_proforma.js +288 -147
- package/lib/actions/create_return_invoice.d.ts +4 -1
- package/lib/actions/create_return_invoice.js +312 -158
- package/lib/actions/create_transfer.d.ts +4 -1
- package/lib/actions/create_transfer.js +223 -126
- 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 +68 -48
- package/lib/commands/brand.d.ts +3 -1
- package/lib/commands/brand.js +174 -100
- 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 +24 -11
- package/lib/commands/index.js +65 -62
- 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 +617 -326
- package/lib/commands/price_list_disabled.d.ts +12 -0
- package/lib/commands/price_list_disabled.js +216 -0
- package/lib/commands/product.d.ts +32 -30
- package/lib/commands/product.js +485 -263
- package/lib/commands/product_disabled.d.ts +3 -1
- package/lib/commands/product_disabled.js +160 -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 +30 -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 +335 -327
- 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 +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/price_list_disabled.d.ts +1 -0
- package/lib/test/commands/price_list_disabled.js +359 -0
- 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 +78 -53
- package/lib/util.d.ts +76 -19
- package/lib/util.js +179 -144
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +7 -18
- package/src/actions/create_proforma.ts +11 -1
- package/src/commands/basic.ts +1 -0
- package/src/commands/index.ts +3 -0
- package/src/commands/price_list.ts +7 -2
- package/src/commands/price_list_disabled.ts +194 -0
- package/src/test/commands/basic.ts +7 -0
- package/src/test/commands/price_list_disabled.ts +362 -0
- package/src/types.ts +1 -0
- package/src/util.ts +18 -1
|
@@ -1,131 +1,210 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
_create,
|
|
4
|
+
update_bench_time,
|
|
5
|
+
date_formatting,
|
|
6
|
+
set_error,
|
|
7
|
+
} from "../util.js";
|
|
3
8
|
export const sync_payment_term = async (commandEvent) => {
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
9
|
+
var _a, _b, _c, _d;
|
|
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;
|
|
42
53
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
method: "update",
|
|
95
|
-
doc_id: repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term._id,
|
|
96
|
-
doc: body,
|
|
97
|
-
error_message: set_error(e),
|
|
98
|
-
});
|
|
99
|
-
result.failed++;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
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
|
+
);
|
|
102
105
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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("Create Payment Term Failed >> ", e?.response, body);
|
|
122
|
+
failed_docs_report.push({
|
|
123
|
+
method: "create",
|
|
124
|
+
doc: body,
|
|
125
|
+
error_message: set_error(e),
|
|
126
|
+
});
|
|
127
|
+
result.failed++;
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
if (
|
|
131
|
+
(repzo_payment_term === null || repzo_payment_term === void 0
|
|
132
|
+
? void 0
|
|
133
|
+
: repzo_payment_term.name) ==
|
|
134
|
+
(body === null || body === void 0 ? void 0 : body.name) &&
|
|
135
|
+
(repzo_payment_term === null || repzo_payment_term === void 0
|
|
136
|
+
? void 0
|
|
137
|
+
: repzo_payment_term.due_days) ==
|
|
138
|
+
(body === null || body === void 0 ? void 0 : body.due_days)
|
|
139
|
+
)
|
|
140
|
+
continue;
|
|
141
|
+
// Update
|
|
142
|
+
try {
|
|
143
|
+
const updated_payment_term = await repzo.paymentTerm.update(
|
|
144
|
+
repzo_payment_term._id,
|
|
145
|
+
body
|
|
146
|
+
);
|
|
147
|
+
result.updated++;
|
|
148
|
+
} catch (e) {
|
|
149
|
+
// console.log(
|
|
150
|
+
// "Update Payment Term Failed >> ",
|
|
151
|
+
// e?.response?.data,
|
|
152
|
+
// body
|
|
153
|
+
// );
|
|
154
|
+
failed_docs_report.push({
|
|
155
|
+
method: "update",
|
|
156
|
+
doc_id:
|
|
157
|
+
repzo_payment_term === null || repzo_payment_term === void 0
|
|
158
|
+
? void 0
|
|
159
|
+
: repzo_payment_term._id,
|
|
160
|
+
doc: body,
|
|
161
|
+
error_message: set_error(e),
|
|
162
|
+
});
|
|
163
|
+
result.failed++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
116
166
|
}
|
|
167
|
+
// console.log(result);
|
|
168
|
+
await update_bench_time(
|
|
169
|
+
repzo,
|
|
170
|
+
commandEvent.app._id,
|
|
171
|
+
bench_time_key,
|
|
172
|
+
new_bench_time
|
|
173
|
+
);
|
|
174
|
+
await commandLog
|
|
175
|
+
.setStatus(
|
|
176
|
+
"success",
|
|
177
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
178
|
+
)
|
|
179
|
+
.setBody(result)
|
|
180
|
+
.commit();
|
|
181
|
+
return result;
|
|
182
|
+
} catch (e) {
|
|
183
|
+
//@ts-ignore
|
|
184
|
+
console.error(
|
|
185
|
+
((_d = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
186
|
+
_d === void 0
|
|
187
|
+
? void 0
|
|
188
|
+
: _d.data) || e
|
|
189
|
+
);
|
|
190
|
+
await commandLog.setStatus("fail", e).commit();
|
|
191
|
+
throw e;
|
|
192
|
+
}
|
|
117
193
|
};
|
|
118
194
|
const get_sap_clients = async (serviceEndPoint, query) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
195
|
+
try {
|
|
196
|
+
const sap_clients = await _create(serviceEndPoint, "/Customers", {
|
|
197
|
+
Active: "Y",
|
|
198
|
+
Frozen: "N",
|
|
199
|
+
UpdateAt: date_formatting(
|
|
200
|
+
query === null || query === void 0 ? void 0 : query.updateAt,
|
|
201
|
+
"YYYYMMDD:HHmmss"
|
|
202
|
+
),
|
|
203
|
+
GroupCode:
|
|
204
|
+
(query === null || query === void 0 ? void 0 : query.GroupCode) || "",
|
|
205
|
+
});
|
|
206
|
+
return sap_clients.Customers;
|
|
207
|
+
} catch (e) {
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
131
210
|
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { CommandEvent } from "../types";
|
|
2
2
|
export declare const sync_price_list: (commandEvent: CommandEvent) => Promise<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
18
|
}>;
|