@accounter/server 0.0.9-alpha-20251216144137-dc7316f892e1fcf0e350cfbbaa9ca0746e1c6c50 → 0.0.9-alpha-20251216161545-668306e40cf3aed663f444e0004246489fbec6d4

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 (51) hide show
  1. package/CHANGELOG.md +5 -28
  2. package/dist/green-invoice-graphql/src/mesh-artifacts/index.d.ts +1 -1
  3. package/dist/server/src/__generated__/types.d.ts +301 -282
  4. package/dist/server/src/__generated__/types.js.map +1 -1
  5. package/dist/server/src/modules/app-providers/green-invoice-client.d.ts +3 -3
  6. package/dist/server/src/modules/documents/__generated__/types.d.ts +7 -121
  7. package/dist/server/src/modules/documents/__generated__/types.js.map +1 -1
  8. package/dist/server/src/modules/documents/helpers/common.helper.d.ts +0 -2
  9. package/dist/server/src/modules/documents/helpers/common.helper.js +0 -20
  10. package/dist/server/src/modules/documents/helpers/common.helper.js.map +1 -1
  11. package/dist/server/src/modules/documents/index.js +2 -9
  12. package/dist/server/src/modules/documents/index.js.map +1 -1
  13. package/dist/server/src/modules/green-invoice/__generated__/types.d.ts +135 -6
  14. package/dist/server/src/modules/green-invoice/__generated__/types.js +2 -0
  15. package/dist/server/src/modules/green-invoice/__generated__/types.js.map +1 -1
  16. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.d.ts +7 -0
  17. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js +53 -0
  18. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js.map +1 -0
  19. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.d.ts +27 -21
  20. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js +146 -151
  21. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js.map +1 -1
  22. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.d.ts +19 -0
  23. package/dist/server/src/modules/{documents → green-invoice}/helpers/issue-document.helper.js +11 -59
  24. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.js.map +1 -0
  25. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +347 -4
  26. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
  27. package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js +512 -4
  28. package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js.map +1 -1
  29. package/dist/shaam-uniform-format-generator/src/generator/records/b110.d.ts +35 -35
  30. package/dist/shaam-uniform-format-generator/src/types/enums.d.ts +71 -71
  31. package/package.json +1 -1
  32. package/src/__generated__/types.ts +620 -327
  33. package/src/modules/documents/__generated__/types.ts +7 -121
  34. package/src/modules/documents/helpers/common.helper.ts +0 -21
  35. package/src/modules/documents/index.ts +2 -9
  36. package/src/modules/green-invoice/__generated__/types.ts +137 -6
  37. package/src/modules/green-invoice/helpers/contract-to-draft.helper.ts +69 -0
  38. package/src/modules/green-invoice/helpers/green-invoice.helper.ts +199 -183
  39. package/src/modules/{documents → green-invoice}/helpers/issue-document.helper.ts +44 -96
  40. package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +520 -5
  41. package/src/modules/green-invoice/typeDefs/green-invoice.graphql.ts +512 -4
  42. package/dist/server/src/modules/documents/helpers/issue-document.helper.d.ts +0 -21
  43. package/dist/server/src/modules/documents/helpers/issue-document.helper.js.map +0 -1
  44. package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.d.ts +0 -2
  45. package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.js +0 -346
  46. package/dist/server/src/modules/documents/resolvers/documents-issuing.resolver.js.map +0 -1
  47. package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.d.ts +0 -2
  48. package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.js +0 -228
  49. package/dist/server/src/modules/documents/typeDefs/documents-issuing.graphql.js.map +0 -1
  50. package/src/modules/documents/resolvers/documents-issuing.resolver.ts +0 -529
  51. package/src/modules/documents/typeDefs/documents-issuing.graphql.ts +0 -228
@@ -2,28 +2,34 @@ import { GraphQLError } from 'graphql';
2
2
  import { Injector } from 'graphql-modules';
3
3
  import type {
4
4
  _DOLLAR_defs_addDocumentRequest_Input,
5
- _DOLLAR_defs_Country,
6
- _DOLLAR_defs_Currency,
7
5
  _DOLLAR_defs_Document,
8
6
  _DOLLAR_defs_DocumentInputNew_Input,
9
7
  _DOLLAR_defs_DocumentLang,
10
8
  _DOLLAR_defs_DocumentLinkedDocument,
11
- _DOLLAR_defs_DocumentType,
12
9
  _DOLLAR_defs_ExpenseDocumentType,
13
10
  _DOLLAR_defs_VatType,
11
+ _DOLLAR_defs_Currency as GreenInvoiceCurrency,
12
+ _DOLLAR_defs_DocumentType as GreenInvoiceDocumentType,
13
+ query_getDocument_payment_items_appType,
14
14
  query_getDocument_payment_items_cardType,
15
+ query_getDocument_payment_items_dealType,
16
+ query_getDocument_payment_items_subType,
15
17
  query_getDocument_payment_items_type,
16
18
  queryInput_previewDocument_input_discount_type,
17
19
  queryInput_previewDocument_input_linkType,
18
20
  } from '@accounter/green-invoice-graphql';
19
21
  import type {
20
- DocumentDiscountType,
21
- DocumentIssueInput,
22
- DocumentLanguage,
23
- DocumentLinkType,
24
- DocumentPaymentRecordCardType,
25
- DocumentVatType,
26
- PaymentType,
22
+ GreenInvoiceCountry,
23
+ GreenInvoiceDiscountType,
24
+ GreenInvoiceDocumentLang,
25
+ GreenInvoiceLinkType,
26
+ GreenInvoicePaymentAppType,
27
+ GreenInvoicePaymentCardType,
28
+ GreenInvoicePaymentDealType,
29
+ GreenInvoicePaymentSubType,
30
+ GreenInvoicePaymentType,
31
+ GreenInvoiceVatType,
32
+ NewDocumentInput,
27
33
  ResolversTypes,
28
34
  } from '../../../__generated__/types.js';
29
35
  import { CountryCode, Currency, DocumentType } from '../../../shared/enums.js';
@@ -37,8 +43,8 @@ import type { document_status, IInsertDocumentsParams } from '../../documents/ty
37
43
  import { validateClientIntegrations } from '../../financial-entities/helpers/clients.helper.js';
38
44
  import { ClientsProvider } from '../../financial-entities/providers/clients.provider.js';
39
45
 
40
- export function normalizeGreenInvoiceDocumentType(
41
- rawType?: _DOLLAR_defs_DocumentType | _DOLLAR_defs_ExpenseDocumentType | number | null,
46
+ export function normalizeDocumentType(
47
+ rawType?: GreenInvoiceDocumentType | _DOLLAR_defs_ExpenseDocumentType | number | null,
42
48
  ): DocumentType {
43
49
  if (!rawType) {
44
50
  return DocumentType.Unprocessed;
@@ -79,7 +85,7 @@ export function normalizeGreenInvoiceDocumentType(
79
85
  }
80
86
  }
81
87
 
82
- export function getGreenInvoiceDocumentType(documentType: DocumentType): _DOLLAR_defs_DocumentType {
88
+ export function getGreenInvoiceDocumentType(documentType: DocumentType): GreenInvoiceDocumentType {
83
89
  switch (documentType) {
84
90
  case DocumentType.Invoice:
85
91
  return '_305';
@@ -97,7 +103,7 @@ export function getGreenInvoiceDocumentType(documentType: DocumentType): _DOLLAR
97
103
  }
98
104
 
99
105
  export function getTypeFromGreenInvoiceDocument(
100
- documentType: _DOLLAR_defs_DocumentType,
106
+ documentType: GreenInvoiceDocumentType,
101
107
  ): DocumentType {
102
108
  switch (documentType) {
103
109
  case '_305':
@@ -115,18 +121,23 @@ export function getTypeFromGreenInvoiceDocument(
115
121
  }
116
122
  }
117
123
 
118
- export function getDocumentNameFromGreenInvoiceType(
119
- documentType: _DOLLAR_defs_DocumentType,
124
+ export function getGreenInvoiceDocumentNameFromType(
125
+ documentType: DocumentType | GreenInvoiceDocumentType,
120
126
  ): string {
121
127
  switch (documentType) {
128
+ case DocumentType.Invoice:
122
129
  case '_305':
123
130
  return 'Tax Invoice';
131
+ case DocumentType.Proforma:
124
132
  case '_300':
125
133
  return 'Proforma Invoice';
134
+ case DocumentType.InvoiceReceipt:
126
135
  case '_320':
127
136
  return 'Invoice / Receipt';
137
+ case DocumentType.CreditInvoice:
128
138
  case '_330':
129
139
  return 'Credit Note';
140
+ case DocumentType.Receipt:
130
141
  case '_400':
131
142
  return 'Receipt';
132
143
  default:
@@ -134,7 +145,9 @@ export function getDocumentNameFromGreenInvoiceType(
134
145
  }
135
146
  }
136
147
 
137
- export function getGreenInvoiceDocumentLanguage(lang: DocumentLanguage): _DOLLAR_defs_DocumentLang {
148
+ export function getGreenInvoiceDocumentLanguage(
149
+ lang: GreenInvoiceDocumentLang,
150
+ ): _DOLLAR_defs_DocumentLang {
138
151
  switch (lang) {
139
152
  case 'HEBREW':
140
153
  return 'he';
@@ -147,7 +160,7 @@ export function getGreenInvoiceDocumentLanguage(lang: DocumentLanguage): _DOLLAR
147
160
 
148
161
  export function getLanguageFromGreenInvoiceDocument(
149
162
  lang: _DOLLAR_defs_DocumentLang,
150
- ): DocumentLanguage {
163
+ ): GreenInvoiceDocumentLang {
151
164
  switch (lang) {
152
165
  case 'he':
153
166
  return 'HEBREW';
@@ -158,7 +171,7 @@ export function getLanguageFromGreenInvoiceDocument(
158
171
  }
159
172
  }
160
173
 
161
- export function getGreenInvoiceDocumentVatType(vatType: DocumentVatType): _DOLLAR_defs_VatType {
174
+ export function getGreenInvoiceDocumentVatType(vatType: GreenInvoiceVatType): _DOLLAR_defs_VatType {
162
175
  switch (vatType) {
163
176
  case 'DEFAULT':
164
177
  return '_0';
@@ -171,7 +184,9 @@ export function getGreenInvoiceDocumentVatType(vatType: DocumentVatType): _DOLLA
171
184
  }
172
185
  }
173
186
 
174
- export function getVatTypeFromGreenInvoiceDocument(vatType: _DOLLAR_defs_VatType): DocumentVatType {
187
+ export function getVatTypeFromGreenInvoiceDocument(
188
+ vatType: _DOLLAR_defs_VatType,
189
+ ): GreenInvoiceVatType {
175
190
  switch (vatType) {
176
191
  case '_0':
177
192
  return 'DEFAULT';
@@ -185,7 +200,7 @@ export function getVatTypeFromGreenInvoiceDocument(vatType: _DOLLAR_defs_VatType
185
200
  }
186
201
 
187
202
  export function getGreenInvoiceDocumentDiscountType(
188
- discountType: DocumentDiscountType,
203
+ discountType: GreenInvoiceDiscountType,
189
204
  ): queryInput_previewDocument_input_discount_type {
190
205
  switch (discountType) {
191
206
  case 'PERCENTAGE':
@@ -198,7 +213,7 @@ export function getGreenInvoiceDocumentDiscountType(
198
213
  }
199
214
 
200
215
  export function getGreenInvoiceDocumentPaymentType(
201
- type: PaymentType,
216
+ type: GreenInvoicePaymentType,
202
217
  ): query_getDocument_payment_items_type {
203
218
  switch (type) {
204
219
  case 'TAX_DEDUCTION':
@@ -226,7 +241,7 @@ export function getGreenInvoiceDocumentPaymentType(
226
241
 
227
242
  export function getTypeFromGreenInvoiceDocumentPayment(
228
243
  type: query_getDocument_payment_items_type,
229
- ): PaymentType {
244
+ ): GreenInvoicePaymentType {
230
245
  switch (type) {
231
246
  case 'NEGATIVE_1':
232
247
  return 'TAX_DEDUCTION';
@@ -251,100 +266,100 @@ export function getTypeFromGreenInvoiceDocumentPayment(
251
266
  }
252
267
  }
253
268
 
254
- // export function getGreenInvoiceDocumentPaymentSubType(
255
- // subType: GreenInvoicePaymentSubType,
256
- // ): query_getDocument_payment_items_subType {
257
- // switch (subType) {
258
- // case 'BITCOIN':
259
- // return '_1';
260
- // case 'BUYME_VOUCHER':
261
- // return '_7';
262
- // case 'ETHEREUM':
263
- // return '_6';
264
- // case 'GIFT_CARD':
265
- // return '_4';
266
- // case 'MONEY_EQUAL':
267
- // return '_2';
268
- // case 'NII_EMPLOYEE_DEDUCTION':
269
- // return '_5';
270
- // case 'PAYONEER':
271
- // return '_8';
272
- // case 'V_CHECK':
273
- // return '_3';
274
- // default:
275
- // throw new Error(`Unsupported payment sub-type: ${subType}`);
276
- // }
277
- // }
269
+ export function getGreenInvoiceDocumentPaymentSubType(
270
+ subType: GreenInvoicePaymentSubType,
271
+ ): query_getDocument_payment_items_subType {
272
+ switch (subType) {
273
+ case 'BITCOIN':
274
+ return '_1';
275
+ case 'BUYME_VOUCHER':
276
+ return '_7';
277
+ case 'ETHEREUM':
278
+ return '_6';
279
+ case 'GIFT_CARD':
280
+ return '_4';
281
+ case 'MONEY_EQUAL':
282
+ return '_2';
283
+ case 'NII_EMPLOYEE_DEDUCTION':
284
+ return '_5';
285
+ case 'PAYONEER':
286
+ return '_8';
287
+ case 'V_CHECK':
288
+ return '_3';
289
+ default:
290
+ throw new Error(`Unsupported payment sub-type: ${subType}`);
291
+ }
292
+ }
278
293
 
279
- // export function getSubTypeFromGreenInvoiceDocumentPayment(
280
- // subType: query_getDocument_payment_items_subType,
281
- // ): GreenInvoicePaymentSubType {
282
- // switch (subType) {
283
- // case '_1':
284
- // return 'BITCOIN';
285
- // case '_7':
286
- // return 'BUYME_VOUCHER';
287
- // case '_6':
288
- // return 'ETHEREUM';
289
- // case '_4':
290
- // return 'GIFT_CARD';
291
- // case '_2':
292
- // return 'MONEY_EQUAL';
293
- // case '_5':
294
- // return 'NII_EMPLOYEE_DEDUCTION';
295
- // case '_8':
296
- // return 'PAYONEER';
297
- // case '_3':
298
- // return 'V_CHECK';
299
- // default:
300
- // throw new Error(`Unsupported payment sub-type: ${subType}`);
301
- // }
302
- // }
294
+ export function getSubTypeFromGreenInvoiceDocumentPayment(
295
+ subType: query_getDocument_payment_items_subType,
296
+ ): GreenInvoicePaymentSubType {
297
+ switch (subType) {
298
+ case '_1':
299
+ return 'BITCOIN';
300
+ case '_7':
301
+ return 'BUYME_VOUCHER';
302
+ case '_6':
303
+ return 'ETHEREUM';
304
+ case '_4':
305
+ return 'GIFT_CARD';
306
+ case '_2':
307
+ return 'MONEY_EQUAL';
308
+ case '_5':
309
+ return 'NII_EMPLOYEE_DEDUCTION';
310
+ case '_8':
311
+ return 'PAYONEER';
312
+ case '_3':
313
+ return 'V_CHECK';
314
+ default:
315
+ throw new Error(`Unsupported payment sub-type: ${subType}`);
316
+ }
317
+ }
303
318
 
304
- // export function getGreenInvoiceDocumentPaymentAppType(
305
- // appType: GreenInvoicePaymentAppType,
306
- // ): query_getDocument_payment_items_appType {
307
- // switch (appType) {
308
- // case 'APPLE_PAY':
309
- // return '_6';
310
- // case 'BIT':
311
- // return '_1';
312
- // case 'CULO':
313
- // return '_4';
314
- // case 'GOOGLE_PAY':
315
- // return '_5';
316
- // case 'PAYBOX':
317
- // return '_3';
318
- // case 'PAY_BY_PEPPER':
319
- // return '_2';
320
- // default:
321
- // throw new Error(`Unsupported payment app type: ${appType}`);
322
- // }
323
- // }
319
+ export function getGreenInvoiceDocumentPaymentAppType(
320
+ appType: GreenInvoicePaymentAppType,
321
+ ): query_getDocument_payment_items_appType {
322
+ switch (appType) {
323
+ case 'APPLE_PAY':
324
+ return '_6';
325
+ case 'BIT':
326
+ return '_1';
327
+ case 'CULO':
328
+ return '_4';
329
+ case 'GOOGLE_PAY':
330
+ return '_5';
331
+ case 'PAYBOX':
332
+ return '_3';
333
+ case 'PAY_BY_PEPPER':
334
+ return '_2';
335
+ default:
336
+ throw new Error(`Unsupported payment app type: ${appType}`);
337
+ }
338
+ }
324
339
 
325
- // export function getPaymentAppTypeFromGreenInvoiceDocument(
326
- // appType: query_getDocument_payment_items_appType,
327
- // ): GreenInvoicePaymentAppType {
328
- // switch (appType) {
329
- // case '_6':
330
- // return 'APPLE_PAY';
331
- // case '_1':
332
- // return 'BIT';
333
- // case '_4':
334
- // return 'CULO';
335
- // case '_5':
336
- // return 'GOOGLE_PAY';
337
- // case '_3':
338
- // return 'PAYBOX';
339
- // case '_2':
340
- // return 'PAY_BY_PEPPER';
341
- // default:
342
- // throw new Error(`Unsupported payment app type: ${appType}`);
343
- // }
344
- // }
340
+ export function getPaymentAppTypeFromGreenInvoiceDocument(
341
+ appType: query_getDocument_payment_items_appType,
342
+ ): GreenInvoicePaymentAppType {
343
+ switch (appType) {
344
+ case '_6':
345
+ return 'APPLE_PAY';
346
+ case '_1':
347
+ return 'BIT';
348
+ case '_4':
349
+ return 'CULO';
350
+ case '_5':
351
+ return 'GOOGLE_PAY';
352
+ case '_3':
353
+ return 'PAYBOX';
354
+ case '_2':
355
+ return 'PAY_BY_PEPPER';
356
+ default:
357
+ throw new Error(`Unsupported payment app type: ${appType}`);
358
+ }
359
+ }
345
360
 
346
361
  export function getGreenInvoiceDocumentPaymentCardType(
347
- cardType: DocumentPaymentRecordCardType,
362
+ cardType: GreenInvoicePaymentCardType,
348
363
  ): query_getDocument_payment_items_cardType {
349
364
  switch (cardType) {
350
365
  case 'AMERICAN_EXPRESS':
@@ -366,7 +381,7 @@ export function getGreenInvoiceDocumentPaymentCardType(
366
381
 
367
382
  export function getCardTypeFromGreenInvoiceDocumentPayment(
368
383
  cardType: query_getDocument_payment_items_cardType,
369
- ): DocumentPaymentRecordCardType {
384
+ ): GreenInvoicePaymentCardType {
370
385
  switch (cardType) {
371
386
  case '_4':
372
387
  return 'AMERICAN_EXPRESS';
@@ -385,50 +400,50 @@ export function getCardTypeFromGreenInvoiceDocumentPayment(
385
400
  }
386
401
  }
387
402
 
388
- // export function getGreenInvoiceDocumentPaymentDealType(
389
- // dealType: GreenInvoicePaymentDealType,
390
- // ): query_getDocument_payment_items_dealType {
391
- // switch (dealType) {
392
- // case 'CREDIT':
393
- // return '_3';
394
- // case 'DEFERRED':
395
- // return '_4';
396
- // case 'OTHER':
397
- // return '_5';
398
- // case 'PAYMENTS':
399
- // return '_2';
400
- // case 'RECURRING':
401
- // return '_6';
402
- // case 'STANDARD':
403
- // return '_1';
404
- // default:
405
- // throw new Error(`Unsupported payment deal type: ${dealType}`);
406
- // }
407
- // }
403
+ export function getGreenInvoiceDocumentPaymentDealType(
404
+ dealType: GreenInvoicePaymentDealType,
405
+ ): query_getDocument_payment_items_dealType {
406
+ switch (dealType) {
407
+ case 'CREDIT':
408
+ return '_3';
409
+ case 'DEFERRED':
410
+ return '_4';
411
+ case 'OTHER':
412
+ return '_5';
413
+ case 'PAYMENTS':
414
+ return '_2';
415
+ case 'RECURRING':
416
+ return '_6';
417
+ case 'STANDARD':
418
+ return '_1';
419
+ default:
420
+ throw new Error(`Unsupported payment deal type: ${dealType}`);
421
+ }
422
+ }
408
423
 
409
- // export function getDealTypeFromGreenInvoiceDocumentPayment(
410
- // dealType: query_getDocument_payment_items_dealType,
411
- // ): GreenInvoicePaymentDealType {
412
- // switch (dealType) {
413
- // case '_3':
414
- // return 'CREDIT';
415
- // case '_4':
416
- // return 'DEFERRED';
417
- // case '_5':
418
- // return 'OTHER';
419
- // case '_2':
420
- // return 'PAYMENTS';
421
- // case '_6':
422
- // return 'RECURRING';
423
- // case '_1':
424
- // return 'STANDARD';
425
- // default:
426
- // throw new Error(`Unsupported payment deal type: ${dealType}`);
427
- // }
428
- // }
424
+ export function getDealTypeFromGreenInvoiceDocumentPayment(
425
+ dealType: query_getDocument_payment_items_dealType,
426
+ ): GreenInvoicePaymentDealType {
427
+ switch (dealType) {
428
+ case '_3':
429
+ return 'CREDIT';
430
+ case '_4':
431
+ return 'DEFERRED';
432
+ case '_5':
433
+ return 'OTHER';
434
+ case '_2':
435
+ return 'PAYMENTS';
436
+ case '_6':
437
+ return 'RECURRING';
438
+ case '_1':
439
+ return 'STANDARD';
440
+ default:
441
+ throw new Error(`Unsupported payment deal type: ${dealType}`);
442
+ }
443
+ }
429
444
 
430
445
  export function getGreenInvoiceDocumentLinkType(
431
- linkType: DocumentLinkType,
446
+ linkType: GreenInvoiceLinkType,
432
447
  ): queryInput_previewDocument_input_linkType {
433
448
  switch (linkType) {
434
449
  case 'CANCEL':
@@ -440,7 +455,7 @@ export function getGreenInvoiceDocumentLinkType(
440
455
  }
441
456
  }
442
457
 
443
- export function convertCurrencyToGreenInvoice(currency: Currency): _DOLLAR_defs_Currency {
458
+ export function convertCurrencyToGreenInvoice(currency: Currency): GreenInvoiceCurrency {
444
459
  switch (currency) {
445
460
  case Currency.Aud:
446
461
  return 'AUD';
@@ -467,8 +482,8 @@ export function convertCurrencyToGreenInvoice(currency: Currency): _DOLLAR_defs_
467
482
  }
468
483
  }
469
484
 
470
- export function greenInvoiceCountryToCountryCode(country: _DOLLAR_defs_Country): CountryCode {
471
- const greenInvoiceToCountryCodeMap: Partial<Record<_DOLLAR_defs_Country, CountryCode>> = {
485
+ export function greenInvoiceCountryToCountryCode(country: GreenInvoiceCountry): CountryCode {
486
+ const greenInvoiceToCountryCodeMap: Partial<Record<GreenInvoiceCountry, CountryCode>> = {
472
487
  AD: CountryCode.Andorra,
473
488
  AE: CountryCode['United Arab Emirates (the)'],
474
489
  AF: CountryCode.Afghanistan,
@@ -731,8 +746,8 @@ export function greenInvoiceCountryToCountryCode(country: _DOLLAR_defs_Country):
731
746
  throw new Error(`Unsupported Green Invoice country: ${country}`);
732
747
  }
733
748
 
734
- export function countryCodeToGreenInvoiceCountry(countryCode: CountryCode): _DOLLAR_defs_Country {
735
- const countryCodeToGreenInvoiceMap: Partial<Record<CountryCode, _DOLLAR_defs_Country>> = {
749
+ export function countryCodeToGreenInvoiceCountry(countryCode: CountryCode): GreenInvoiceCountry {
750
+ const countryCodeToGreenInvoiceMap: Partial<Record<CountryCode, GreenInvoiceCountry>> = {
736
751
  [CountryCode.Afghanistan]: 'AF',
737
752
  [CountryCode['Åland Islands']]: 'AX',
738
753
  [CountryCode.Albania]: 'AL',
@@ -1052,7 +1067,7 @@ export async function insertNewDocumentFromGreenInvoice(
1052
1067
  ownerId: string,
1053
1068
  preDictatedChargeId?: string | null,
1054
1069
  ) {
1055
- const documentType = normalizeGreenInvoiceDocumentType(greenInvoiceDoc.type);
1070
+ const documentType = normalizeDocumentType(greenInvoiceDoc.type);
1056
1071
  const isOwnerCreditor = greenInvoiceDoc.amount > 0 && documentType !== DocumentType.CreditInvoice;
1057
1072
 
1058
1073
  const links = await injector.get(GreenInvoiceClientProvider).getDocumentLinks(greenInvoiceDoc.id);
@@ -1225,16 +1240,16 @@ export async function getGreenInvoiceDocuments(injector: Injector, recursive: bo
1225
1240
  }
1226
1241
 
1227
1242
  export async function convertDocumentInputIntoGreenInvoiceInput(
1228
- initialInput: DocumentIssueInput,
1243
+ initialInput: NewDocumentInput,
1229
1244
  injector: Injector,
1230
1245
  ): Promise<_DOLLAR_defs_DocumentInputNew_Input> {
1231
1246
  let client: _DOLLAR_defs_addDocumentRequest_Input['client'] | undefined = undefined;
1232
1247
  if (initialInput.client) {
1233
1248
  const clientInfo = await injector
1234
1249
  .get(ClientsProvider)
1235
- .getClientByIdLoader.load(initialInput.client.id);
1250
+ .getClientByIdLoader.load(initialInput.client.businessId);
1236
1251
  if (!clientInfo) {
1237
- throw new GraphQLError(`Client with business ID ${initialInput.client.id} not found`);
1252
+ throw new GraphQLError(`Client with ID ${initialInput.client.greenInvoiceId} not found`);
1238
1253
  }
1239
1254
  let greenInvoiceId: string | null = null;
1240
1255
  try {
@@ -1243,12 +1258,12 @@ export async function convertDocumentInputIntoGreenInvoiceInput(
1243
1258
  } catch (error) {
1244
1259
  console.error('Failed to validate client integrations', error);
1245
1260
  throw new GraphQLError(
1246
- `Client with business ID ${initialInput.client.id} has invalid integrations`,
1261
+ `Client with ID ${initialInput.client.greenInvoiceId} has invalid integrations`,
1247
1262
  );
1248
1263
  }
1249
1264
  if (!greenInvoiceId) {
1250
1265
  throw new GraphQLError(
1251
- `Client with business ID ${initialInput.client.id} not found in Green Invoice`,
1266
+ `Client with ID ${initialInput.client.greenInvoiceId} not found in Green Invoice`,
1252
1267
  );
1253
1268
  }
1254
1269
  const greenInvoiceClient = await injector
@@ -1264,7 +1279,6 @@ export async function convertDocumentInputIntoGreenInvoiceInput(
1264
1279
  } else {
1265
1280
  emails.push(...(greenInvoiceClient.emails ?? []));
1266
1281
  }
1267
- // TODO: use local values
1268
1282
  client = {
1269
1283
  id: greenInvoiceClient.id,
1270
1284
  country: greenInvoiceClient.country,
@@ -1284,7 +1298,7 @@ export async function convertDocumentInputIntoGreenInvoiceInput(
1284
1298
  ...initialInput,
1285
1299
  currency: convertCurrencyToGreenInvoice(initialInput.currency),
1286
1300
  type: getGreenInvoiceDocumentType(initialInput.type),
1287
- lang: getGreenInvoiceDocumentLanguage(initialInput.language),
1301
+ lang: getGreenInvoiceDocumentLanguage(initialInput.lang),
1288
1302
  vatType: getGreenInvoiceDocumentVatType(initialInput.vatType ?? 'DEFAULT'),
1289
1303
  discount: initialInput.discount
1290
1304
  ? {
@@ -1302,12 +1316,14 @@ export async function convertDocumentInputIntoGreenInvoiceInput(
1302
1316
  payment: initialInput.payment?.map(payment => ({
1303
1317
  ...payment,
1304
1318
  type: getGreenInvoiceDocumentPaymentType(payment.type),
1305
- subType: undefined,
1306
- appType: undefined,
1319
+ subType: payment.subType ? getGreenInvoiceDocumentPaymentSubType(payment.subType) : undefined,
1320
+ appType: payment.appType ? getGreenInvoiceDocumentPaymentAppType(payment.appType) : undefined,
1307
1321
  cardType: payment.cardType
1308
1322
  ? getGreenInvoiceDocumentPaymentCardType(payment.cardType)
1309
1323
  : undefined,
1310
- dealType: undefined,
1324
+ dealType: payment.dealType
1325
+ ? getGreenInvoiceDocumentPaymentDealType(payment.dealType)
1326
+ : undefined,
1311
1327
  currency: convertCurrencyToGreenInvoice(payment.currency),
1312
1328
  })),
1313
1329
  linkedDocumentIds: initialInput.linkedDocumentIds?.length
@@ -1319,34 +1335,34 @@ export async function convertDocumentInputIntoGreenInvoiceInput(
1319
1335
  };
1320
1336
  }
1321
1337
 
1322
- export async function convertGreenInvoiceDocumentToDocumentDraft(
1338
+ export function convertGreenInvoiceDocumentToLocalDocumentInfo(
1323
1339
  greenInvoiceDocument: _DOLLAR_defs_Document,
1324
- injector: Injector,
1325
- ): Promise<ResolversTypes['DocumentDraft']> {
1326
- const client = await (greenInvoiceDocument.client?.id
1327
- ? injector
1328
- .get(ClientsProvider)
1329
- .getClientByGreenInvoiceIdLoader.load(greenInvoiceDocument.client?.id)
1330
- : Promise.resolve(undefined));
1340
+ ): ResolversTypes['NewDocumentInfo'] {
1331
1341
  return {
1332
1342
  ...greenInvoiceDocument,
1333
- client,
1343
+ client: greenInvoiceDocument.client?.id,
1334
1344
  currency: greenInvoiceDocument.currency as Currency,
1335
1345
  income: greenInvoiceDocument.income?.filter(Boolean).map(income => ({
1336
1346
  ...income!,
1337
1347
  currency: income!.currency as Currency,
1338
1348
  vatType: getVatTypeFromGreenInvoiceDocument(income!.vatType),
1339
1349
  })),
1340
- language: getLanguageFromGreenInvoiceDocument(greenInvoiceDocument.lang),
1350
+ lang: getLanguageFromGreenInvoiceDocument(greenInvoiceDocument.lang),
1341
1351
  payment: greenInvoiceDocument.payment?.filter(Boolean).map(payment => ({
1342
1352
  ...payment!,
1343
- appType: undefined,
1353
+ appType: payment?.appType
1354
+ ? getPaymentAppTypeFromGreenInvoiceDocument(payment.appType)
1355
+ : undefined,
1344
1356
  cardType: payment?.cardType
1345
1357
  ? getCardTypeFromGreenInvoiceDocumentPayment(payment.cardType)
1346
1358
  : undefined,
1347
1359
  currency: payment!.currency as Currency,
1348
- dealType: undefined,
1349
- subType: undefined,
1360
+ dealType: payment?.dealType
1361
+ ? getDealTypeFromGreenInvoiceDocumentPayment(payment.dealType)
1362
+ : undefined,
1363
+ subType: payment?.subType
1364
+ ? getSubTypeFromGreenInvoiceDocumentPayment(payment.subType)
1365
+ : undefined,
1350
1366
  type: getTypeFromGreenInvoiceDocumentPayment(payment!.type),
1351
1367
  })),
1352
1368
  type: getTypeFromGreenInvoiceDocument(greenInvoiceDocument.type),