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.
Files changed (75) hide show
  1. package/lib/actions/create_invoice.d.ts +13 -19
  2. package/lib/actions/create_invoice.js +207 -365
  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
@@ -4,203 +4,115 @@ 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(
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;
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;
23
12
  try {
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
- await repzo.updateIntegrationMeta.create(
33
- [
34
- { key: "sync_to_sap_started", value: true },
35
- { key: "sync_to_sap_succeeded", value: false },
36
- ],
37
- { _id: body._id, type: "payments" }
38
- );
39
- } catch (e) {
40
- console.error(e);
41
- }
42
- await actionLog
43
- .addDetail(
44
- `Payment - ${repzo_serial_number} => ${
45
- body === null || body === void 0 ? void 0 : body.sync_id
46
- }`
47
- )
48
- .addDetail(
49
- `Repzo => SAP: Started Create Payment - ${repzo_serial_number}`
50
- )
51
- .commit();
52
- const SAP_HOST_URL =
53
- (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
54
- if (!SAP_HOST_URL)
55
- throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
56
- const repzo_payment = body;
57
- // Get Repzo Rep
58
- let repzo_rep;
59
- if (repzo_payment.creator.type == "rep") {
60
- repzo_rep = await repzo.rep.get(
61
- (_e =
62
- repzo_payment === null || repzo_payment === void 0
63
- ? void 0
64
- : repzo_payment.creator) === null || _e === void 0
65
- ? void 0
66
- : _e._id
67
- );
68
- if (!repzo_rep)
69
- throw `Rep with _id: ${repzo_payment.creator._id} not found in Repzo`;
70
- }
71
- // Get Repzo Client
72
- const repzo_client = await repzo.client.get(
73
- repzo_payment === null || repzo_payment === void 0
74
- ? void 0
75
- : repzo_payment.client_id
76
- );
77
- if (!repzo_client)
78
- throw `Client with _id: ${repzo_payment.client_id} not found in Repzo`;
79
- const sap_payment = {
80
- UserId:
81
- repzo_rep === null || repzo_rep === void 0
82
- ? void 0
83
- : repzo_rep.integration_id,
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 = "";
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
+ await repzo.updateIntegrationMeta.create([
24
+ { key: "sync_to_sap_started", value: true },
25
+ { key: "sync_to_sap_succeeded", value: false },
26
+ ], { _id: body._id, type: "payments" });
27
+ }
28
+ catch (e) {
29
+ console.error(e);
30
+ }
31
+ await actionLog
32
+ .addDetail(`Payment - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
33
+ .addDetail(`Repzo => SAP: Started Create Payment - ${repzo_serial_number}`)
34
+ .commit();
35
+ const SAP_HOST_URL = (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
36
+ if (!SAP_HOST_URL)
37
+ throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
38
+ const repzo_payment = body;
39
+ // Get Repzo Rep
40
+ let repzo_rep;
41
+ if (repzo_payment.creator.type == "rep") {
42
+ 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);
43
+ if (!repzo_rep)
44
+ throw `Rep with _id: ${repzo_payment.creator._id} not found in Repzo`;
45
+ }
46
+ // Get Repzo Client
47
+ const repzo_client = await repzo.client.get(repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.client_id);
48
+ if (!repzo_client)
49
+ throw `Client with _id: ${repzo_payment.client_id} not found in Repzo`;
50
+ const sap_payment = {
51
+ UserId: repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_id,
52
+ PaymentID: repzo_serial_number,
53
+ ClientCode: repzo_client === null || repzo_client === void 0 ? void 0 : repzo_client.client_code,
54
+ PaymentDate: moment(repzo_payment.paytime, "YYYY-MM-DD").format("YYYYMMDD"),
55
+ Amount: repzo_payment.amount / 1000,
56
+ };
57
+ if (repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) {
58
+ const sap_open_invoices = await get_invoice_from_sap(SAP_HOST_URL, {
59
+ updatedAt: "",
60
+ Status: "",
61
+ 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,
62
+ });
63
+ if (!(sap_open_invoices === null || sap_open_invoices === void 0 ? void 0 : sap_open_invoices.length)) {
64
+ throw `Invoice with serial number: ${repzo_payment.LinkedTxn.Txn_serial_number.formatted} was not found on SAP or was closed`;
65
+ }
66
+ sap_payment.InvoiceID = sap_open_invoices[0].InvoiceID;
67
+ sap_payment.InvoiceTotal =
68
+ ((_h = repzo_payment === null || repzo_payment === void 0 ? void 0 : repzo_payment.LinkedTxn) === null || _h === void 0 ? void 0 : _h.Txn_invoice_total) / 1000;
69
+ }
70
+ else {
71
+ sap_payment.InvoiceID = "";
72
+ sap_payment.InvoiceTotal = "";
73
+ }
74
+ if (repzo_payment.payment_type == "check") {
75
+ // bank
76
+ //@ts-ignore
77
+ const repzo_bank = await repzo.bank.get((_j = repzo_payment.check) === null || _j === void 0 ? void 0 : _j.bank);
78
+ if (!repzo_bank) {
79
+ //@ts-ignore
80
+ throw `Bank with _id: ${repzo_payment.check.bank} not found in Repzo`;
81
+ }
82
+ sap_payment.PaymentType = "2";
83
+ sap_payment.ChequeAccount =
84
+ (_k = repzo_rep === null || repzo_rep === void 0 ? void 0 : repzo_rep.integration_meta) === null || _k === void 0 ? void 0 : _k.USERCHECKACCTCODE;
85
+ sap_payment.ChequeDate = moment((_l = repzo_payment.check) === null || _l === void 0 ? void 0 : _l.check_date, "YYYY-MM-DD").format("YYYYMMDD");
86
+ sap_payment.ChequeNumber = (_m = repzo_payment.check) === null || _m === void 0 ? void 0 : _m.check_number;
87
+ sap_payment.BankCode = (_o = repzo_bank.integration_meta) === null || _o === void 0 ? void 0 : _o.BANKCODE;
88
+ sap_payment.CountryCode = (_p = repzo_bank.integration_meta) === null || _p === void 0 ? void 0 : _p.COUNTRY;
89
+ }
90
+ else if (repzo_payment.payment_type == "cash") {
91
+ sap_payment.PaymentType = "1";
92
+ 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;
93
+ }
94
+ // console.dir(sap_payment, { depth: null });
95
+ actionLog.addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`, sap_payment);
96
+ const result = await _create(SAP_HOST_URL, "/AddPayment", sap_payment);
97
+ // console.log(result);
98
+ try {
99
+ await repzo.updateIntegrationMeta.create([{ key: "sync_to_sap_succeeded", value: true }], { _id: body._id, type: "payments" });
100
+ }
101
+ catch (e) {
102
+ console.error(e);
103
+ }
104
+ await actionLog
105
+ .addDetail(`SAP Responded with `, result)
106
+ .addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`)
107
+ .setStatus("success")
108
+ .setBody(repzo_payment)
109
+ .commit();
110
+ return result;
131
111
  }
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) {
112
+ catch (e) {
139
113
  //@ts-ignore
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
- await repzo.updateIntegrationMeta.create(
187
- [{ key: "sync_to_sap_succeeded", value: true }],
188
- { _id: body._id, type: "payments" }
189
- );
190
- } catch (e) {
191
- console.error(e);
114
+ console.error((e === null || e === void 0 ? void 0 : e.response) || e);
115
+ await actionLog.setStatus("fail", e).setBody(body).commit();
116
+ throw e;
192
117
  }
193
- await actionLog
194
- .addDetail(`SAP Responded with `, result)
195
- .addDetail(`Repzo => SAP: Payment - ${repzo_serial_number}`)
196
- .setStatus("success")
197
- .setBody(repzo_payment)
198
- .commit();
199
- return result;
200
- } catch (e) {
201
- //@ts-ignore
202
- console.error((e === null || e === void 0 ? void 0 : e.response) || e);
203
- await actionLog.setStatus("fail", e).setBody(body).commit();
204
- throw e;
205
- }
206
118
  };
@@ -1,5 +1,2 @@
1
1
  import { EVENT, Config } from "../types";
2
- export declare const create_proforma: (
3
- event: EVENT,
4
- options: Config
5
- ) => Promise<any>;
2
+ export declare const create_proforma: (event: EVENT, options: Config) => Promise<any>;