repzo-sap-absjo 1.0.8 → 1.0.9

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 (77) hide show
  1. package/lib/actions/create_invoice.d.ts +19 -13
  2. package/lib/actions/create_invoice.js +363 -214
  3. package/lib/actions/create_payment.d.ts +4 -1
  4. package/lib/actions/create_payment.js +200 -125
  5. package/lib/actions/create_proforma.d.ts +4 -1
  6. package/lib/actions/create_proforma.js +290 -165
  7. package/lib/actions/create_return_invoice.d.ts +4 -1
  8. package/lib/actions/create_return_invoice.js +321 -177
  9. package/lib/actions/create_transfer.d.ts +4 -1
  10. package/lib/actions/create_transfer.js +220 -143
  11. package/lib/actions/index.js +23 -15
  12. package/lib/commands/adjust_inventory.d.ts +4 -2
  13. package/lib/commands/adjust_inventory.js +290 -160
  14. package/lib/commands/bank.d.ts +4 -2
  15. package/lib/commands/bank.js +279 -157
  16. package/lib/commands/basic.js +66 -47
  17. package/lib/commands/category.d.ts +3 -1
  18. package/lib/commands/category.js +178 -104
  19. package/lib/commands/channel.d.ts +3 -1
  20. package/lib/commands/channel.js +198 -117
  21. package/lib/commands/client.d.ts +34 -32
  22. package/lib/commands/client.js +404 -244
  23. package/lib/commands/client_disabled.d.ts +3 -1
  24. package/lib/commands/client_disabled.js +163 -94
  25. package/lib/commands/index.d.ts +15 -11
  26. package/lib/commands/index.js +60 -60
  27. package/lib/commands/join.js +192 -66
  28. package/lib/commands/measureunit.d.ts +19 -14
  29. package/lib/commands/measureunit.js +289 -191
  30. package/lib/commands/measureunit_family.d.ts +10 -8
  31. package/lib/commands/measureunit_family.js +250 -138
  32. package/lib/commands/payment_term.d.ts +3 -1
  33. package/lib/commands/payment_term.js +202 -123
  34. package/lib/commands/price_list.d.ts +15 -15
  35. package/lib/commands/price_list.js +612 -326
  36. package/lib/commands/product.d.ts +32 -30
  37. package/lib/commands/product.js +425 -243
  38. package/lib/commands/product_disabled.d.ts +3 -1
  39. package/lib/commands/product_disabled.js +164 -94
  40. package/lib/commands/rep.js +221 -141
  41. package/lib/commands/tag.js +174 -109
  42. package/lib/commands/tax.js +177 -112
  43. package/lib/commands/warehouse.d.ts +3 -1
  44. package/lib/commands/warehouse.js +207 -119
  45. package/lib/index.d.ts +21 -12
  46. package/lib/test/actions/create_invoice.js +193 -188
  47. package/lib/test/actions/create_payment.js +112 -107
  48. package/lib/test/actions/create_proforma.js +220 -216
  49. package/lib/test/actions/create_return_invoice.js +205 -200
  50. package/lib/test/actions/create_transfer.js +120 -115
  51. package/lib/test/commands/adjust_inventory.js +90 -90
  52. package/lib/test/commands/bank.js +90 -90
  53. package/lib/test/commands/basic.js +328 -327
  54. package/lib/test/commands/category.js +90 -90
  55. package/lib/test/commands/channel.js +90 -90
  56. package/lib/test/commands/client.js +355 -353
  57. package/lib/test/commands/client_disabled.js +90 -90
  58. package/lib/test/commands/join.js +328 -327
  59. package/lib/test/commands/measureunit.js +90 -90
  60. package/lib/test/commands/measureunit_family.js +90 -90
  61. package/lib/test/commands/payment_term.js +90 -90
  62. package/lib/test/commands/price_list.js +337 -334
  63. package/lib/test/commands/product.js +90 -90
  64. package/lib/test/commands/product_disabled.js +90 -90
  65. package/lib/test/commands/rep.js +346 -344
  66. package/lib/test/commands/tag.js +90 -90
  67. package/lib/test/commands/tax.js +90 -90
  68. package/lib/test/commands/warehouse.js +90 -90
  69. package/lib/types.d.ts +83 -60
  70. package/lib/util.d.ts +70 -19
  71. package/lib/util.js +170 -144
  72. package/package.json +1 -1
  73. package/src/actions/create_invoice.ts +4 -13
  74. package/src/actions/create_payment.ts +4 -13
  75. package/src/actions/create_proforma.ts +28 -40
  76. package/src/actions/create_return_invoice.ts +4 -16
  77. package/src/actions/create_transfer.ts +24 -36
@@ -4,133 +4,208 @@ import { v4 as uuid } from "uuid";
4
4
  import moment from "moment-timezone";
5
5
  import { get_invoice_from_sap } from "./create_invoice.js";
6
6
  export const create_payment = async (event, options) => {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
8
- const repzo = new Repzo((_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey, { env: options.env });
9
- const action_sync_id = ((_b = event === null || event === void 0 ? void 0 : event.headers) === null || _b === void 0 ? void 0 : _b.action_sync_id) || uuid();
10
- const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
11
- let body;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
8
+ const repzo = new Repzo(
9
+ (_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
10
+ { env: options.env }
11
+ );
12
+ const action_sync_id =
13
+ ((_b = event === null || event === void 0 ? void 0 : event.headers) ===
14
+ null || _b === void 0
15
+ ? void 0
16
+ : _b.action_sync_id) || uuid();
17
+ const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
18
+ let body;
19
+ try {
20
+ // console.log("create_payment");
21
+ await actionLog.load(action_sync_id);
22
+ body = event.body;
12
23
  try {
13
- // console.log("create_payment");
14
- await actionLog.load(action_sync_id);
15
- body = event.body;
16
- try {
17
- if (body)
18
- body = JSON.parse(body);
19
- }
20
- catch (e) { }
21
- const repzo_serial_number = (_c = body === null || body === void 0 ? void 0 : body.serial_number) === null || _c === void 0 ? void 0 : _c.formatted;
22
- try {
23
- if (body === null || body === void 0 ? void 0 : body._id) {
24
- body.integration_meta = (body === null || body === void 0 ? void 0 : body.integration_meta) || {};
25
- body.integration_meta.sync_to_sap_started = true;
26
- body.integration_meta.sync_to_sap_succeeded =
27
- body.integration_meta.sync_to_sap_succeeded || false;
28
- await repzo.payment.update(body._id, {
29
- integration_meta: body.integration_meta,
30
- });
31
- }
32
- }
33
- catch (e) {
34
- console.error(e);
35
- await actionLog
36
- .addDetail(`Failed updating integration_meta of Payment: ${repzo_serial_number}`)
37
- .commit();
38
- }
39
- await actionLog
40
- .addDetail(`Payment - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
41
- .addDetail(`Repzo => SAP: Started Create Payment - ${repzo_serial_number}`)
42
- .commit();
43
- const SAP_HOST_URL = (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
44
- if (!SAP_HOST_URL)
45
- throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
46
- const repzo_payment = body;
47
- // Get Repzo Rep
48
- let repzo_rep;
49
- if (repzo_payment.creator.type == "rep") {
50
- repzo_rep = await repzo.rep.get((_e = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.creator) === null || _e === void 0 ? void 0 : _e._id);
51
- if (!repzo_rep)
52
- throw `Rep with _id: ${repzo_payment.creator._id} not found in Repzo`;
53
- }
54
- // Get Repzo Client
55
- const repzo_client = await repzo.client.get(repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.client_id);
56
- if (!repzo_client)
57
- throw `Client with _id: ${repzo_payment.client_id} not found in Repzo`;
58
- const sap_payment = {
59
- PaymentID: repzo_serial_number,
60
- ClientCode: repzo_client === null || repzo_client === void 0 ? void 0 : repzo_client.client_code,
61
- PaymentDate: moment(repzo_payment.paytime, "YYYY-MM-DD").format("YYYYMMDD"),
62
- Amount: repzo_payment.amount / 1000,
63
- };
64
- if (repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) {
65
- const sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
66
- updatedAt: "",
67
- Status: "",
68
- InvoiceId: (_g = (_f = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) === null || _f === void 0 ? void 0 : _f.Txn_serial_number) === null || _g === void 0 ? void 0 : _g.formatted,
69
- });
70
- if (!(sap_open_invoices === null || sap_open_invoices === void 0 ? void 0 : sap_open_invoices.length)) {
71
- throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on SAP or was closed`;
72
- }
73
- sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
74
- sap_payment.InvoiceTotal =
75
- ((_h = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) === null || _h === void 0 ? void 0 : _h.Txn_invoice_total) / 1000;
76
- }
77
- else {
78
- sap_payment.InvoiceID = "";
79
- sap_payment.InvoiceTotal = "";
80
- }
81
- if (repzo_payment.payment_type == "check") {
82
- // bank
83
- //@ts-ignore
84
- const repzo_bank = await repzo.bank.get((_j = repzo_payment.check) === null || _j === void 0 ? void 0 : _j.bank);
85
- if (!repzo_bank) {
86
- //@ts-ignore
87
- throw `Bank with _id: ${repzo_payment.check.bank} not found in Repzo`;
88
- }
89
- sap_payment.PaymentType = "2";
90
- sap_payment.ChequeAccount =
91
- (_k = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _k === void 0 ? void 0 : _k.USERCHECKACCTCODE;
92
- sap_payment.ChequeDate = moment((_l = repzo_payment.check) === null || _l === void 0 ? void 0 : _l.check_date, "YYYY-MM-DD").format("YYYYMMDD");
93
- sap_payment.ChequeNumber = (_m = repzo_payment.check) === null || _m === void 0 ? void 0 : _m.check_number;
94
- sap_payment.BankCode = (_o = repzo_bank.integration_meta) === null || _o === void 0 ? void 0 : _o.BANKCODE;
95
- sap_payment.CountryCode = (_p = repzo_bank.integration_meta) === null || _p === void 0 ? void 0 : _p.COUNTRY;
96
- }
97
- else if (repzo_payment.payment_type == "cash") {
98
- sap_payment.PaymentType = "1";
99
- sap_payment.CashAccount = (_q = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _q === void 0 ? void 0 : _q.USERCASHACCOUNT;
100
- }
101
- // console.dir(sap_payment, { depth: null });
102
- await actionLog
103
- .addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`, sap_payment)
104
- .commit();
105
- const result = await _create(SAP_HOST_URL, "/AddPayment", sap_payment);
106
- // console.log(result);
107
- try {
108
- if (body === null || body === void 0 ? void 0 : body._id) {
109
- body.integration_meta = (body === null || body === void 0 ? void 0 : body.integration_meta) || {};
110
- body.integration_meta.sync_to_sap_succeeded = true;
111
- await repzo.payment.update(body._id, {
112
- integration_meta: body.integration_meta,
113
- });
114
- }
115
- }
116
- catch (e) {
117
- console.error(e);
118
- await actionLog
119
- .addDetail(`Failed updating integration_meta of Payment: ${repzo_serial_number}`)
120
- .commit();
121
- }
122
- await actionLog
123
- .addDetail(`SAP Responded with `, result)
124
- .addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`)
125
- .setStatus("success")
126
- .setBody(repzo_payment)
127
- .commit();
128
- return result;
24
+ if (body) body = JSON.parse(body);
25
+ } catch (e) {}
26
+ const repzo_serial_number =
27
+ (_c = body === null || body === void 0 ? void 0 : body.serial_number) ===
28
+ null || _c === void 0
29
+ ? void 0
30
+ : _c.formatted;
31
+ try {
32
+ if (body === null || body === void 0 ? void 0 : body._id) {
33
+ body.integration_meta =
34
+ (body === null || body === void 0 ? void 0 : body.integration_meta) ||
35
+ {};
36
+ body.integration_meta.sync_to_sap_started = true;
37
+ body.integration_meta.sync_to_sap_succeeded =
38
+ body.integration_meta.sync_to_sap_succeeded || false;
39
+ await repzo.payment.update(body._id, {
40
+ integration_meta: body.integration_meta,
41
+ });
42
+ }
43
+ } catch (e) {
44
+ console.error(e);
45
+ }
46
+ await actionLog
47
+ .addDetail(
48
+ `Payment - ${repzo_serial_number} => ${
49
+ body === null || body === void 0 ? void 0 : body.sync_id
50
+ }`
51
+ )
52
+ .addDetail(
53
+ `Repzo => SAP: Started Create Payment - ${repzo_serial_number}`
54
+ )
55
+ .commit();
56
+ const SAP_HOST_URL =
57
+ (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
58
+ if (!SAP_HOST_URL)
59
+ throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
60
+ const repzo_payment = body;
61
+ // Get Repzo Rep
62
+ let repzo_rep;
63
+ if (repzo_payment.creator.type == "rep") {
64
+ repzo_rep = await repzo.rep.get(
65
+ (_e =
66
+ repzo_payment === null || repzo_payment === void 0
67
+ ? void 0
68
+ : repzo_payment.creator) === null || _e === void 0
69
+ ? void 0
70
+ : _e._id
71
+ );
72
+ if (!repzo_rep)
73
+ throw `Rep with _id: ${repzo_payment.creator._id} not found in Repzo`;
74
+ }
75
+ // Get Repzo Client
76
+ const repzo_client = await repzo.client.get(
77
+ repzo_payment === null || repzo_payment === void 0
78
+ ? void 0
79
+ : repzo_payment.client_id
80
+ );
81
+ if (!repzo_client)
82
+ throw `Client with _id: ${repzo_payment.client_id} not found in Repzo`;
83
+ const sap_payment = {
84
+ PaymentID: repzo_serial_number,
85
+ ClientCode:
86
+ repzo_client === null || repzo_client === void 0
87
+ ? void 0
88
+ : repzo_client.client_code,
89
+ PaymentDate: moment(repzo_payment.paytime, "YYYY-MM-DD").format(
90
+ "YYYYMMDD"
91
+ ),
92
+ Amount: repzo_payment.amount / 1000,
93
+ };
94
+ if (
95
+ repzo_payment === null || repzo_payment === void 0
96
+ ? void 0
97
+ : repzo_payment.LinkedTxn
98
+ ) {
99
+ const sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
100
+ updatedAt: "",
101
+ Status: "",
102
+ InvoiceId:
103
+ (_g =
104
+ (_f =
105
+ repzo_payment === null || repzo_payment === void 0
106
+ ? void 0
107
+ : repzo_payment.LinkedTxn) === null || _f === void 0
108
+ ? void 0
109
+ : _f.Txn_serial_number) === null || _g === void 0
110
+ ? void 0
111
+ : _g.formatted,
112
+ });
113
+ if (
114
+ !(sap_open_invoices === null || sap_open_invoices === void 0
115
+ ? void 0
116
+ : sap_open_invoices.length)
117
+ ) {
118
+ throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on SAP or was closed`;
119
+ }
120
+ sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
121
+ sap_payment.InvoiceTotal =
122
+ ((_h =
123
+ repzo_payment === null || repzo_payment === void 0
124
+ ? void 0
125
+ : repzo_payment.LinkedTxn) === null || _h === void 0
126
+ ? void 0
127
+ : _h.Txn_invoice_total) / 1000;
128
+ } else {
129
+ sap_payment.InvoiceID = "";
130
+ sap_payment.InvoiceTotal = "";
129
131
  }
130
- catch (e) {
132
+ if (repzo_payment.payment_type == "check") {
133
+ // bank
134
+ //@ts-ignore
135
+ const repzo_bank = await repzo.bank.get(
136
+ (_j = repzo_payment.check) === null || _j === void 0 ? void 0 : _j.bank
137
+ );
138
+ if (!repzo_bank) {
131
139
  //@ts-ignore
132
- console.error((e === null || e === void 0 ? void 0 : e.response) || e);
133
- await actionLog.setStatus("fail", e).setBody(body).commit();
134
- throw e;
140
+ throw `Bank with _id: ${repzo_payment.check.bank} not found in Repzo`;
141
+ }
142
+ sap_payment.PaymentType = "2";
143
+ sap_payment.ChequeAccount =
144
+ (_k =
145
+ repzo_rep === null || repzo_rep === void 0
146
+ ? void 0
147
+ : repzo_rep.integration_meta) === null || _k === void 0
148
+ ? void 0
149
+ : _k.USERCHECKACCTCODE;
150
+ sap_payment.ChequeDate = moment(
151
+ (_l = repzo_payment.check) === null || _l === void 0
152
+ ? void 0
153
+ : _l.check_date,
154
+ "YYYY-MM-DD"
155
+ ).format("YYYYMMDD");
156
+ sap_payment.ChequeNumber =
157
+ (_m = repzo_payment.check) === null || _m === void 0
158
+ ? void 0
159
+ : _m.check_number;
160
+ sap_payment.BankCode =
161
+ (_o = repzo_bank.integration_meta) === null || _o === void 0
162
+ ? void 0
163
+ : _o.BANKCODE;
164
+ sap_payment.CountryCode =
165
+ (_p = repzo_bank.integration_meta) === null || _p === void 0
166
+ ? void 0
167
+ : _p.COUNTRY;
168
+ } else if (repzo_payment.payment_type == "cash") {
169
+ sap_payment.PaymentType = "1";
170
+ sap_payment.CashAccount =
171
+ (_q =
172
+ repzo_rep === null || repzo_rep === void 0
173
+ ? void 0
174
+ : repzo_rep.integration_meta) === null || _q === void 0
175
+ ? void 0
176
+ : _q.USERCASHACCOUNT;
177
+ }
178
+ // console.dir(sap_payment, { depth: null });
179
+ actionLog.addDetail(
180
+ `Repzo => SAP: Payment - ${repzo_serial_number}`,
181
+ sap_payment
182
+ );
183
+ const result = await _create(SAP_HOST_URL, "/AddPayment", sap_payment);
184
+ // console.log(result);
185
+ try {
186
+ if (body === null || body === void 0 ? void 0 : body._id) {
187
+ body.integration_meta =
188
+ (body === null || body === void 0 ? void 0 : body.integration_meta) ||
189
+ {};
190
+ body.integration_meta.sync_to_sap_succeeded = true;
191
+ await repzo.payment.update(body._id, {
192
+ integration_meta: body.integration_meta,
193
+ });
194
+ }
195
+ } catch (e) {
196
+ console.error(e);
135
197
  }
198
+ await actionLog
199
+ .addDetail(`SAP Responded with `, result)
200
+ .addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`)
201
+ .setStatus("success")
202
+ .setBody(repzo_payment)
203
+ .commit();
204
+ return result;
205
+ } catch (e) {
206
+ //@ts-ignore
207
+ console.error((e === null || e === void 0 ? void 0 : e.response) || e);
208
+ await actionLog.setStatus("fail", e).setBody(body).commit();
209
+ throw e;
210
+ }
136
211
  };
@@ -1,2 +1,5 @@
1
1
  import { EVENT, Config } from "../types";
2
- export declare const create_proforma: (event: EVENT, options: Config) => Promise<any>;
2
+ export declare const create_proforma: (
3
+ event: EVENT,
4
+ options: Config
5
+ ) => Promise<any>;