repzo-sap-absjo 1.0.19 → 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.
Files changed (76) hide show
  1. package/lib/actions/create_invoice.d.ts +13 -19
  2. package/lib/actions/create_invoice.js +207 -377
  3. package/lib/actions/create_payment.d.ts +1 -4
  4. package/lib/actions/create_payment.js +107 -195
  5. package/lib/actions/create_proforma.d.ts +1 -4
  6. package/lib/actions/create_proforma.js +146 -285
  7. package/lib/actions/create_return_invoice.d.ts +1 -4
  8. package/lib/actions/create_return_invoice.js +158 -312
  9. package/lib/actions/create_transfer.d.ts +1 -4
  10. package/lib/actions/create_transfer.js +126 -223
  11. package/lib/actions/index.js +15 -23
  12. package/lib/commands/adjust_inventory.d.ts +2 -4
  13. package/lib/commands/adjust_inventory.js +160 -290
  14. package/lib/commands/bank.d.ts +2 -4
  15. package/lib/commands/bank.js +157 -279
  16. package/lib/commands/basic.js +48 -67
  17. package/lib/commands/brand.d.ts +1 -3
  18. package/lib/commands/brand.js +100 -174
  19. package/lib/commands/category.d.ts +1 -3
  20. package/lib/commands/category.js +104 -178
  21. package/lib/commands/channel.d.ts +1 -3
  22. package/lib/commands/channel.js +117 -198
  23. package/lib/commands/client.d.ts +32 -34
  24. package/lib/commands/client.js +244 -404
  25. package/lib/commands/client_disabled.d.ts +1 -3
  26. package/lib/commands/client_disabled.js +94 -163
  27. package/lib/commands/index.d.ts +11 -15
  28. package/lib/commands/index.js +62 -62
  29. package/lib/commands/join.js +66 -192
  30. package/lib/commands/measureunit.d.ts +14 -19
  31. package/lib/commands/measureunit.js +191 -289
  32. package/lib/commands/measureunit_family.d.ts +8 -10
  33. package/lib/commands/measureunit_family.js +138 -250
  34. package/lib/commands/payment_term.d.ts +1 -3
  35. package/lib/commands/payment_term.js +123 -202
  36. package/lib/commands/price_list.d.ts +15 -15
  37. package/lib/commands/price_list.js +326 -612
  38. package/lib/commands/product.d.ts +30 -32
  39. package/lib/commands/product.js +263 -485
  40. package/lib/commands/product_disabled.d.ts +1 -3
  41. package/lib/commands/product_disabled.js +94 -160
  42. package/lib/commands/rep.js +141 -221
  43. package/lib/commands/tag.js +109 -174
  44. package/lib/commands/tax.js +112 -177
  45. package/lib/commands/warehouse.d.ts +1 -3
  46. package/lib/commands/warehouse.js +119 -207
  47. package/lib/index.d.ts +12 -21
  48. package/lib/test/actions/create_invoice.js +188 -193
  49. package/lib/test/actions/create_payment.js +107 -112
  50. package/lib/test/actions/create_proforma.js +216 -220
  51. package/lib/test/actions/create_return_invoice.js +200 -205
  52. package/lib/test/actions/create_transfer.js +115 -120
  53. package/lib/test/commands/adjust_inventory.js +90 -90
  54. package/lib/test/commands/bank.js +90 -90
  55. package/lib/test/commands/basic.js +327 -328
  56. package/lib/test/commands/brand.js +90 -90
  57. package/lib/test/commands/category.js +90 -90
  58. package/lib/test/commands/channel.js +90 -90
  59. package/lib/test/commands/client.js +353 -355
  60. package/lib/test/commands/client_disabled.js +90 -90
  61. package/lib/test/commands/join.js +327 -328
  62. package/lib/test/commands/measureunit.js +90 -90
  63. package/lib/test/commands/measureunit_family.js +90 -90
  64. package/lib/test/commands/payment_term.js +90 -90
  65. package/lib/test/commands/price_list.js +334 -337
  66. package/lib/test/commands/product.js +90 -90
  67. package/lib/test/commands/product_disabled.js +90 -90
  68. package/lib/test/commands/rep.js +344 -346
  69. package/lib/test/commands/tag.js +90 -90
  70. package/lib/test/commands/tax.js +90 -90
  71. package/lib/test/commands/warehouse.js +90 -90
  72. package/lib/types.d.ts +53 -77
  73. package/lib/util.d.ts +19 -70
  74. package/lib/util.js +144 -170
  75. package/package.json +1 -1
  76. package/src/actions/create_invoice.ts +5 -25
@@ -1,210 +1,131 @@
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_payment_term = async (commandEvent) => {
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;
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,
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,
68
7
  });
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("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++;
8
+ const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
9
+ try {
10
+ // console.log("sync_payment_term");
11
+ const new_bench_time = new Date().toISOString();
12
+ const bench_time_key = "bench_time_payment_term";
13
+ await commandLog.load(commandEvent.sync_id);
14
+ await commandLog
15
+ .addDetail("Repzo SAP: Started Syncing Payments Term")
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,
29
+ });
30
+ const sap_unique_payment_terms = {};
31
+ sap_clients === null || sap_clients === void 0 ? void 0 : sap_clients.forEach((client) => {
32
+ const paymentTerm = client.PAYMENTTERM;
33
+ sap_unique_payment_terms[paymentTerm] = true;
34
+ });
35
+ const sap_payment_terms = Object.keys(sap_unique_payment_terms);
36
+ result.sap_total = sap_payment_terms === null || sap_payment_terms === void 0 ? void 0 : sap_payment_terms.length;
37
+ await commandLog
38
+ .addDetail(`${result.sap_total} Payments Term in SAP changed since ${commandEvent.app.options_formData[bench_time_key] || "ever"}`)
39
+ .commit();
40
+ const repzo_payment_terms = await repzo.paymentTerm.find({
41
+ per_page: 50000,
42
+ });
43
+ result.repzo_total = (_b = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _b === void 0 ? void 0 : _b.length;
44
+ await commandLog
45
+ .addDetail(`${(_c = repzo_payment_terms === null || repzo_payment_terms === void 0 ? void 0 : repzo_payment_terms.data) === null || _c === void 0 ? void 0 : _c.length} Payments Term in Repzo`)
46
+ .commit();
47
+ for (let i = 0; i < (sap_payment_terms === null || sap_payment_terms === void 0 ? void 0 : sap_payment_terms.length); i++) {
48
+ const sap_payment_term = sap_payment_terms[i];
49
+ const repzo_payment_term = repzo_payment_terms.data.find((r_payment_term) => {
50
+ var _a;
51
+ return ((_a = r_payment_term.integration_meta) === null || _a === void 0 ? void 0 : _a.id) ==
52
+ `${nameSpace}_${sap_payment_term}`;
53
+ });
54
+ const body = {
55
+ name: sap_payment_term.toString(),
56
+ due_days: Number(sap_payment_term),
57
+ integration_meta: {
58
+ id: `${nameSpace}_${sap_payment_term}`,
59
+ },
60
+ company_namespace: [nameSpace],
61
+ };
62
+ if (!repzo_payment_term) {
63
+ // Create
64
+ try {
65
+ const created_payment_term = await repzo.paymentTerm.create(body);
66
+ result.created++;
67
+ }
68
+ catch (e) {
69
+ // console.log("Create Payment Term 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
+ if ((repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term.name) == (body === null || body === void 0 ? void 0 : body.name) &&
80
+ (repzo_payment_term === null || repzo_payment_term === void 0 ? void 0 : repzo_payment_term.due_days) == (body === null || body === void 0 ? void 0 : body.due_days))
81
+ continue;
82
+ // Update
83
+ try {
84
+ const updated_payment_term = await repzo.paymentTerm.update(repzo_payment_term._id, body);
85
+ result.updated++;
86
+ }
87
+ catch (e) {
88
+ // console.log(
89
+ // "Update Payment Term Failed >> ",
90
+ // e?.response?.data,
91
+ // body
92
+ // );
93
+ failed_docs_report.push({
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
+ }
164
102
  }
165
- }
103
+ // console.log(result);
104
+ await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
105
+ await commandLog
106
+ .setStatus("success", failed_docs_report.length ? failed_docs_report : null)
107
+ .setBody(result)
108
+ .commit();
109
+ return result;
110
+ }
111
+ catch (e) {
112
+ //@ts-ignore
113
+ console.error(((_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) || e);
114
+ await commandLog.setStatus("fail", e).commit();
115
+ throw e;
166
116
  }
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
- }
193
117
  };
194
118
  const get_sap_clients = async (serviceEndPoint, query) => {
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
- }
119
+ try {
120
+ const sap_clients = await _create(serviceEndPoint, "/Customers", {
121
+ Active: "Y",
122
+ Frozen: "N",
123
+ UpdateAt: date_formatting(query === null || query === void 0 ? void 0 : query.updateAt, "YYYYMMDD:HHmmss"),
124
+ GroupCode: (query === null || query === void 0 ? void 0 : query.GroupCode) || "",
125
+ });
126
+ return sap_clients.Customers;
127
+ }
128
+ catch (e) {
129
+ throw e;
130
+ }
210
131
  };
@@ -1,18 +1,18 @@
1
1
  import { CommandEvent } from "../types";
2
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;
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
  }>;