@accounter/server 0.0.8-alpha-20251102160658-6d41b0a7bb225382246645badf39a28bcd8102e1 → 0.0.8-alpha-20251102162844-adaba3b25910083f6ebd80bd580629e1c0871260

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 (43) hide show
  1. package/CHANGELOG.md +21 -5
  2. package/dist/green-invoice-graphql/src/mesh-artifacts/index.d.ts +1191 -1444
  3. package/dist/green-invoice-graphql/src/mesh-artifacts/index.js +427 -614
  4. package/dist/green-invoice-graphql/src/mesh-artifacts/index.js.map +1 -1
  5. package/dist/green-invoice-graphql/src/mesh-artifacts/sources/GreenInvoice/schemaWithAnnotations.js +9268 -11080
  6. package/dist/green-invoice-graphql/src/mesh-artifacts/sources/GreenInvoice/schemaWithAnnotations.js.map +1 -1
  7. package/dist/green-invoice-graphql/src/mesh-artifacts/sources/GreenInvoice/types.d.ts +639 -776
  8. package/dist/green-invoice-graphql/src/mesh-artifacts/sources/GreenInvoiceNew/schemaWithAnnotations.js +8 -8
  9. package/dist/green-invoice-graphql/src/mesh-artifacts/sources/GreenInvoiceNew/schemaWithAnnotations.js.map +1 -1
  10. package/dist/green-invoice-graphql/src/mesh-artifacts/sources/GreenInvoiceNew/types.d.ts +8 -8
  11. package/dist/server/src/modules/app-providers/green-invoice-client.d.ts +24 -28
  12. package/dist/server/src/modules/app-providers/green-invoice-client.js +1 -67
  13. package/dist/server/src/modules/app-providers/green-invoice-client.js.map +1 -1
  14. package/dist/server/src/modules/countries/types.d.ts +0 -251
  15. package/dist/server/src/modules/countries/types.js +0 -252
  16. package/dist/server/src/modules/countries/types.js.map +1 -1
  17. package/dist/server/src/modules/financial-entities/resolvers/businesses.resolver.js +2 -6
  18. package/dist/server/src/modules/financial-entities/resolvers/businesses.resolver.js.map +1 -1
  19. package/dist/server/src/modules/financial-entities/resolvers/clients.resolvers.js +0 -5
  20. package/dist/server/src/modules/financial-entities/resolvers/clients.resolvers.js.map +1 -1
  21. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js +1 -1
  22. package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js.map +1 -1
  23. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.d.ts +23 -26
  24. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js +4 -1018
  25. package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js.map +1 -1
  26. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.d.ts +5 -4
  27. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.js +29 -0
  28. package/dist/server/src/modules/green-invoice/helpers/issue-document.helper.js.map +1 -1
  29. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +1 -2
  30. package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/modules/app-providers/green-invoice-client.ts +1 -82
  33. package/src/modules/countries/types.ts +0 -252
  34. package/src/modules/financial-entities/resolvers/businesses.resolver.ts +2 -10
  35. package/src/modules/financial-entities/resolvers/clients.resolvers.ts +0 -11
  36. package/src/modules/green-invoice/helpers/contract-to-draft.helper.ts +1 -1
  37. package/src/modules/green-invoice/helpers/green-invoice.helper.ts +43 -1066
  38. package/src/modules/green-invoice/helpers/issue-document.helper.ts +41 -3
  39. package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +6 -6
  40. package/dist/server/src/modules/green-invoice/helpers/green-invoice-clients.helper.d.ts +0 -5
  41. package/dist/server/src/modules/green-invoice/helpers/green-invoice-clients.helper.js +0 -192
  42. package/dist/server/src/modules/green-invoice/helpers/green-invoice-clients.helper.js.map +0 -1
  43. package/src/modules/green-invoice/helpers/green-invoice-clients.helper.ts +0 -239
@@ -1,6 +1,6 @@
1
1
  import { GraphQLError } from 'graphql';
2
2
  import { Injector } from 'graphql-modules';
3
- import type { _DOLLAR_defs_Document } from '@accounter/green-invoice-graphql';
3
+ import type { Document } from '@accounter/green-invoice-graphql';
4
4
  import { GreenInvoiceClientProvider } from '@modules/app-providers/green-invoice-client.js';
5
5
  import { ChargesProvider } from '@modules/charges/providers/charges.provider.js';
6
6
  import { IssuedDocumentsProvider } from '@modules/documents/providers/issued-documents.provider.js';
@@ -10,10 +10,12 @@ import {
10
10
  } from '@modules/documents/types';
11
11
  import { FinancialAccountsProvider } from '@modules/financial-accounts/providers/financial-accounts.provider.js';
12
12
  import { BusinessesProvider } from '@modules/financial-entities/providers/businesses.provider.js';
13
+ import { ClientsProvider } from '@modules/financial-entities/providers/clients.provider.js';
13
14
  import { IGetTransactionsByChargeIdsResult } from '@modules/transactions/types';
14
15
  import { DocumentType } from '@shared/enums';
15
16
  import {
16
17
  Currency,
18
+ GreenInvoiceClient,
17
19
  GreenInvoiceIncome,
18
20
  GreenInvoiceLinkType,
19
21
  GreenInvoicePayment,
@@ -127,7 +129,7 @@ export function getIncomeFromDocuments(
127
129
  documents: {
128
130
  document: IGetDocumentsByChargeIdResult;
129
131
  issuedDocument: IGetIssuedDocumentsByIdsResult;
130
- greenInvoiceDocument: _DOLLAR_defs_Document;
132
+ greenInvoiceDocument: Document;
131
133
  }[],
132
134
  ): GreenInvoiceIncome[] {
133
135
  const incomes = documents
@@ -154,7 +156,7 @@ export function getIncomeFromDocuments(
154
156
  }
155
157
 
156
158
  export function getTypeFromDocumentsAndTransactions(
157
- greenInvoiceDocuments: _DOLLAR_defs_Document[],
159
+ greenInvoiceDocuments: Document[],
158
160
  transactions: IGetTransactionsByChargeIdsResult[],
159
161
  ): DocumentType {
160
162
  if (!greenInvoiceDocuments.length) {
@@ -249,6 +251,42 @@ export function getDocumentDateOutOfTransactions(
249
251
  return dateToTimelessDateString(firstDate);
250
252
  }
251
253
 
254
+ export async function getClientFromGreenInvoiceClient(
255
+ injector: Injector,
256
+ businessId: string,
257
+ useGreenInvoiceId = false,
258
+ ): Promise<GreenInvoiceClient | undefined> {
259
+ const client = await injector.get(ClientsProvider).getClientByIdLoader.load(businessId);
260
+ if (!client) {
261
+ return useGreenInvoiceId ? undefined : { id: businessId };
262
+ }
263
+
264
+ const greenInvoiceClient = await injector
265
+ .get(GreenInvoiceClientProvider)
266
+ .clientLoader.load(client.green_invoice_id);
267
+
268
+ if (!greenInvoiceClient) {
269
+ return useGreenInvoiceId ? undefined : { id: businessId };
270
+ }
271
+
272
+ return {
273
+ id: useGreenInvoiceId && greenInvoiceClient.id ? greenInvoiceClient.id : businessId,
274
+ country: greenInvoiceClient.country,
275
+ emails: [
276
+ ...((greenInvoiceClient.emails?.filter(Boolean) as string[]) ?? []),
277
+ 'ap@the-guild.dev',
278
+ ],
279
+ name: greenInvoiceClient.name,
280
+ phone: greenInvoiceClient.phone,
281
+ taxId: greenInvoiceClient.taxId,
282
+ address: greenInvoiceClient.address,
283
+ city: greenInvoiceClient.city,
284
+ zip: greenInvoiceClient.zip,
285
+ fax: greenInvoiceClient.fax,
286
+ mobile: greenInvoiceClient.mobile,
287
+ };
288
+ }
289
+
252
290
  export async function deduceVatTypeFromBusiness(
253
291
  injector: Injector,
254
292
  locality: string,
@@ -1,6 +1,6 @@
1
1
  import { addMonths, endOfMonth, format, startOfMonth, subMonths } from 'date-fns';
2
2
  import { GraphQLError } from 'graphql';
3
- import type { _DOLLAR_defs_Document } from '@accounter/green-invoice-graphql';
3
+ import type { Document } from '@accounter/green-invoice-graphql';
4
4
  import { GreenInvoiceClientProvider } from '@modules/app-providers/green-invoice-client.js';
5
5
  import { ChargesProvider } from '@modules/charges/providers/charges.provider.js';
6
6
  import { ContractsProvider } from '@modules/contracts/providers/contracts.provider.js';
@@ -30,11 +30,11 @@ import { Currency, DocumentType } from '@shared/enums';
30
30
  import { NewDocumentInfo } from '@shared/gql-types';
31
31
  import { dateToTimelessDateString } from '@shared/helpers';
32
32
  import { convertContractToDraft } from '../helpers/contract-to-draft.helper.js';
33
- import { getClientFromGreenInvoiceClient } from '../helpers/green-invoice-clients.helper.js';
34
33
  import {
35
34
  deduceVatTypeFromBusiness,
36
35
  executeDocumentIssue,
37
36
  filterAndHandleSwiftTransactions,
37
+ getClientFromGreenInvoiceClient,
38
38
  getDocumentDateOutOfTransactions,
39
39
  getIncomeFromDocuments,
40
40
  getLinkedDocumentsAttributes,
@@ -134,7 +134,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
134
134
  return res;
135
135
  }),
136
136
  ),
137
- ).then(res => res.filter(Boolean) as _DOLLAR_defs_Document[]);
137
+ ).then(res => res.filter(Boolean) as Document[]);
138
138
 
139
139
  const income = getIncomeFromDocuments(
140
140
  openIssuedDocuments.map(doc => ({
@@ -268,7 +268,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
268
268
  throw new GraphQLError(`Document with ID "${document.id}" is closed`);
269
269
  }
270
270
 
271
- const greenInvoiceDocumentPromise: Promise<_DOLLAR_defs_Document | null> = injector
271
+ const greenInvoiceDocumentPromise: Promise<Document | null> = injector
272
272
  .get(GreenInvoiceClientProvider)
273
273
  .documentLoader.load(openIssuedDocument.external_id)
274
274
  .then(res => {
@@ -479,10 +479,10 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
479
479
  const issuedDocuments = await injector.get(IssuedDocumentsProvider).getAllIssuedDocuments();
480
480
 
481
481
  // check for new or updated documents
482
- const newDocuments: _DOLLAR_defs_Document[] = [];
482
+ const newDocuments: Document[] = [];
483
483
  const documentToUpdate: {
484
484
  localDoc: IGetAllIssuedDocumentsResult;
485
- externalDoc: _DOLLAR_defs_Document;
485
+ externalDoc: Document;
486
486
  }[] = [];
487
487
  await Promise.all(
488
488
  greenInvoiceDocuments.map(async item => {
@@ -1,5 +0,0 @@
1
- import { Injector } from 'graphql-modules';
2
- import { ClientUpdateInput, GreenInvoiceClient, UpdateBusinessInput } from '../../../__generated__/types.js';
3
- export declare function getClientFromGreenInvoiceClient(injector: Injector, businessId: string, useGreenInvoiceId?: boolean): Promise<GreenInvoiceClient | undefined>;
4
- export declare function addGreenInvoiceClient(clientId: string, injector: Injector): Promise<void>;
5
- export declare function updateGreenInvoiceClient(clientId: string, injector: Injector, businessFields?: UpdateBusinessInput, clientFields?: ClientUpdateInput): Promise<void>;
@@ -1,192 +0,0 @@
1
- import { GreenInvoiceClientProvider } from '../../app-providers/green-invoice-client.js';
2
- import { BusinessesProvider } from '../../financial-entities/providers/businesses.provider.js';
3
- import { ClientsProvider } from '../../financial-entities/providers/clients.provider.js';
4
- import { countryCodeToGreenInvoiceCountry } from './green-invoice.helper.js';
5
- export async function getClientFromGreenInvoiceClient(injector, businessId, useGreenInvoiceId = false) {
6
- const client = await injector.get(ClientsProvider).getClientByIdLoader.load(businessId);
7
- if (!client) {
8
- return useGreenInvoiceId ? undefined : { id: businessId };
9
- }
10
- const greenInvoiceClient = await injector
11
- .get(GreenInvoiceClientProvider)
12
- .clientLoader.load(client.green_invoice_id);
13
- if (!greenInvoiceClient) {
14
- return useGreenInvoiceId ? undefined : { id: businessId };
15
- }
16
- return {
17
- id: useGreenInvoiceId && greenInvoiceClient.id ? greenInvoiceClient.id : businessId,
18
- country: greenInvoiceClient.country,
19
- emails: [
20
- ...(greenInvoiceClient.emails?.filter(Boolean) ?? []),
21
- 'ap@the-guild.dev',
22
- ],
23
- name: greenInvoiceClient.name,
24
- phone: greenInvoiceClient.phone,
25
- taxId: greenInvoiceClient.taxId,
26
- address: greenInvoiceClient.address,
27
- city: greenInvoiceClient.city,
28
- zip: greenInvoiceClient.zip,
29
- fax: greenInvoiceClient.fax,
30
- mobile: greenInvoiceClient.mobile,
31
- };
32
- }
33
- function convertLocalClientToGreenInvoiceCreateClientInput(localClient, localBusiness) {
34
- return {
35
- /** Phone number */
36
- phone: localBusiness.phone_number,
37
- /** Mobile number */
38
- // mobile: localBusiness.mobile_number,
39
- /** Email addresses */
40
- emails: localClient.emails,
41
- /** Fax number */
42
- // fax: localBusiness.fax_number,
43
- /** Contact person name */
44
- // contactPerson: localBusiness.contact_person,
45
- /** Street address */
46
- address: localBusiness.address,
47
- /** City name */
48
- // city: localBusiness.city,
49
- /** Zip/postal code */
50
- // zip: localBusiness.zip_code,
51
- country: countryCodeToGreenInvoiceCountry(localBusiness.country),
52
- /** Bank name */
53
- // bankName: localBusiness.bank_name,
54
- /** Bank branch number */
55
- // bankBranch: localBusiness.bank_branch_number,
56
- /** Bank account number */
57
- // bankAccount: localBusiness.bank_account_number,
58
- /** The client name */
59
- name: localBusiness.name,
60
- /** Is the client currently active or not */
61
- active: localBusiness.is_active,
62
- /** The client tax ID */
63
- // taxId: localBusiness.tax_id
64
- // paymentTerms: localClient.payment_terms,
65
- // labels: localClient.labels,
66
- /** Whether to send emails to the user automatically when assigning him to an invoice or not */
67
- // send: localClient.send,
68
- /** The client department */
69
- // department: localClient.department,
70
- /** The client accounting key */
71
- accountingKey: localBusiness.sort_code?.toString(),
72
- /** The category this client is related to */
73
- // category: localClient.category,
74
- /** The sub category this client is related to */
75
- // subCategory: localClient.sub_category,
76
- /** Client remarks for self use */
77
- // remarks: localClient.remarks,
78
- };
79
- }
80
- export async function addGreenInvoiceClient(clientId, injector) {
81
- try {
82
- // validate local client
83
- const localBusinessPromise = injector
84
- .get(BusinessesProvider)
85
- .getBusinessByIdLoader.load(clientId);
86
- const localClientPromise = injector.get(ClientsProvider).getClientByIdLoader.load(clientId);
87
- const [localBusiness, localClient] = await Promise.all([
88
- localBusinessPromise,
89
- localClientPromise,
90
- ]);
91
- if (!localBusiness) {
92
- throw new Error('Business not found');
93
- }
94
- if (!localClient) {
95
- throw new Error('Client not found');
96
- }
97
- // validate details
98
- const greenInvoiceCreatClientInput = convertLocalClientToGreenInvoiceCreateClientInput(localClient, localBusiness);
99
- // add to green invoice
100
- const greenInvoiceClient = await injector
101
- .get(GreenInvoiceClientProvider)
102
- .createClient(greenInvoiceCreatClientInput);
103
- if (!greenInvoiceClient?.id) {
104
- throw new Error('Failed to create Green Invoice client');
105
- }
106
- // add green invoice id to local client
107
- await injector.get(ClientsProvider).updateClient({
108
- businessId: clientId,
109
- greenInvoiceId: greenInvoiceClient.id,
110
- });
111
- }
112
- catch (error) {
113
- console.error('Error adding Green Invoice client:', error);
114
- }
115
- }
116
- function pickGreenInvoiceClientFields(businessFields, clientFields) {
117
- const fieldsToUpdate = {
118
- /** Phone number */
119
- phone: businessFields.phoneNumber,
120
- /** Mobile number */
121
- // mobile: businessFields.mobile_number,
122
- /** Email addresses */
123
- emails: clientFields.emails ? [...clientFields.emails] : undefined,
124
- /** Fax number */
125
- // fax: businessFields.fax_number,
126
- /** Contact person name */
127
- // contactPerson: businessFields.contact_person,
128
- /** Street address */
129
- address: businessFields.address ?? undefined,
130
- /** City name */
131
- // city: businessFields.city,
132
- /** Zip/postal code */
133
- // zip: businessFields.zip_code,
134
- country: businessFields.country
135
- ? countryCodeToGreenInvoiceCountry(businessFields.country)
136
- : undefined,
137
- /** Bank name */
138
- // bankName: businessFields.bank_name,
139
- /** Bank branch number */
140
- // bankBranch: businessFields.bank_branch_number,
141
- /** Bank account number */
142
- // bankAccount: businessFields.bank_account_number,
143
- /** The client name */
144
- name: businessFields.name ?? undefined,
145
- /** Is the client currently active or not */
146
- active: businessFields.isActive,
147
- /** The client tax ID */
148
- // taxId: businessFields.tax_id
149
- // paymentTerms: clientFields.payment_terms,
150
- // labels: clientFields.labels,
151
- /** Whether to send emails to the user automatically when assigning him to an invoice or not */
152
- // send: clientFields.send,
153
- /** The client department */
154
- // department: clientFields.department,
155
- /** The client accounting key */
156
- accountingKey: businessFields.sortCode?.toString(),
157
- /** The category this client is related to */
158
- // category: clientFields.category,
159
- /** The sub category this client is related to */
160
- // subCategory: clientFields.sub_category,
161
- /** Client remarks for self use */
162
- // remarks: clientFields.remarks,
163
- };
164
- return fieldsToUpdate;
165
- }
166
- export async function updateGreenInvoiceClient(clientId, injector, businessFields = {}, clientFields = {}) {
167
- // validate local client
168
- const localBusinessPromise = injector
169
- .get(BusinessesProvider)
170
- .getBusinessByIdLoader.load(clientId);
171
- const localClientPromise = injector.get(ClientsProvider).getClientByIdLoader.load(clientId);
172
- const [localBusiness, localClient] = await Promise.all([
173
- localBusinessPromise,
174
- localClientPromise,
175
- ]);
176
- if (!localBusiness?.name || !localClient) {
177
- return;
178
- }
179
- const fieldsToUpdate = pickGreenInvoiceClientFields({ ...businessFields, name: localBusiness.name }, clientFields);
180
- if (Object.keys(fieldsToUpdate).length === 0) {
181
- return;
182
- }
183
- const greenInvoiceClient = await injector.get(GreenInvoiceClientProvider).updateClient({
184
- id: clientId,
185
- input: fieldsToUpdate,
186
- });
187
- if (!greenInvoiceClient?.id) {
188
- throw new Error('Failed to create Green Invoice client');
189
- }
190
- return;
191
- }
192
- //# sourceMappingURL=green-invoice-clients.helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"green-invoice-clients.helper.js","sourceRoot":"","sources":["../../../../../../src/modules/green-invoice/helpers/green-invoice-clients.helper.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAE5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,8DAA8D,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,2DAA2D,CAAC;AAM5F,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAE7E,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,QAAkB,EAClB,UAAkB,EAClB,iBAAiB,GAAG,KAAK;IAEzB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC;IAC5D,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAM,QAAQ;SACtC,GAAG,CAAC,0BAA0B,CAAC;SAC/B,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAg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,CAAC,0BAA0B,CAAC,CAAC,YAAY,CAAC;QACrF,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,cAAc;KACtB,CAAC,CAAC;IAEH,IAAI,CAAC,kBAAkB,EAAE,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO;AACT,CAAC"}
@@ -1,239 +0,0 @@
1
- import { Injector } from 'graphql-modules';
2
- import {
3
- _DOLLAR_defs_addClientRequest_Input,
4
- _DOLLAR_defs_updateClientRequest_Input,
5
- } from '@accounter/green-invoice-graphql';
6
- import { GreenInvoiceClientProvider } from '@modules/app-providers/green-invoice-client.js';
7
- import { CountryCode } from '@modules/countries/types.js';
8
- import { BusinessesProvider } from '@modules/financial-entities/providers/businesses.provider.js';
9
- import { ClientsProvider } from '@modules/financial-entities/providers/clients.provider.js';
10
- import {
11
- IGetBusinessesByIdsResult,
12
- IGetClientsByIdsResult,
13
- } from '@modules/financial-entities/types.js';
14
- import { ClientUpdateInput, GreenInvoiceClient, UpdateBusinessInput } from '@shared/gql-types';
15
- import { countryCodeToGreenInvoiceCountry } from './green-invoice.helper.js';
16
-
17
- export async function getClientFromGreenInvoiceClient(
18
- injector: Injector,
19
- businessId: string,
20
- useGreenInvoiceId = false,
21
- ): Promise<GreenInvoiceClient | undefined> {
22
- const client = await injector.get(ClientsProvider).getClientByIdLoader.load(businessId);
23
- if (!client) {
24
- return useGreenInvoiceId ? undefined : { id: businessId };
25
- }
26
-
27
- const greenInvoiceClient = await injector
28
- .get(GreenInvoiceClientProvider)
29
- .clientLoader.load(client.green_invoice_id);
30
-
31
- if (!greenInvoiceClient) {
32
- return useGreenInvoiceId ? undefined : { id: businessId };
33
- }
34
-
35
- return {
36
- id: useGreenInvoiceId && greenInvoiceClient.id ? greenInvoiceClient.id : businessId,
37
- country: greenInvoiceClient.country,
38
- emails: [
39
- ...((greenInvoiceClient.emails?.filter(Boolean) as string[]) ?? []),
40
- 'ap@the-guild.dev',
41
- ],
42
- name: greenInvoiceClient.name,
43
- phone: greenInvoiceClient.phone,
44
- taxId: greenInvoiceClient.taxId,
45
- address: greenInvoiceClient.address,
46
- city: greenInvoiceClient.city,
47
- zip: greenInvoiceClient.zip,
48
- fax: greenInvoiceClient.fax,
49
- mobile: greenInvoiceClient.mobile,
50
- };
51
- }
52
-
53
- function convertLocalClientToGreenInvoiceCreateClientInput(
54
- localClient: IGetClientsByIdsResult,
55
- localBusiness: IGetBusinessesByIdsResult,
56
- ): _DOLLAR_defs_addClientRequest_Input {
57
- return {
58
- /** Phone number */
59
- phone: localBusiness.phone_number,
60
- /** Mobile number */
61
- // mobile: localBusiness.mobile_number,
62
- /** Email addresses */
63
- emails: localClient.emails,
64
- /** Fax number */
65
- // fax: localBusiness.fax_number,
66
- /** Contact person name */
67
- // contactPerson: localBusiness.contact_person,
68
- /** Street address */
69
- address: localBusiness.address,
70
- /** City name */
71
- // city: localBusiness.city,
72
- /** Zip/postal code */
73
- // zip: localBusiness.zip_code,
74
- country: countryCodeToGreenInvoiceCountry(localBusiness.country as CountryCode),
75
- /** Bank name */
76
- // bankName: localBusiness.bank_name,
77
- /** Bank branch number */
78
- // bankBranch: localBusiness.bank_branch_number,
79
- /** Bank account number */
80
- // bankAccount: localBusiness.bank_account_number,
81
- /** The client name */
82
- name: localBusiness.name,
83
- /** Is the client currently active or not */
84
- active: localBusiness.is_active,
85
- /** The client tax ID */
86
- // taxId: localBusiness.tax_id
87
- // paymentTerms: localClient.payment_terms,
88
- // labels: localClient.labels,
89
- /** Whether to send emails to the user automatically when assigning him to an invoice or not */
90
- // send: localClient.send,
91
- /** The client department */
92
- // department: localClient.department,
93
- /** The client accounting key */
94
- accountingKey: localBusiness.sort_code?.toString(),
95
- /** The category this client is related to */
96
- // category: localClient.category,
97
- /** The sub category this client is related to */
98
- // subCategory: localClient.sub_category,
99
- /** Client remarks for self use */
100
- // remarks: localClient.remarks,
101
- };
102
- }
103
-
104
- export async function addGreenInvoiceClient(clientId: string, injector: Injector): Promise<void> {
105
- try {
106
- // validate local client
107
- const localBusinessPromise = injector
108
- .get(BusinessesProvider)
109
- .getBusinessByIdLoader.load(clientId);
110
- const localClientPromise = injector.get(ClientsProvider).getClientByIdLoader.load(clientId);
111
- const [localBusiness, localClient] = await Promise.all([
112
- localBusinessPromise,
113
- localClientPromise,
114
- ]);
115
- if (!localBusiness) {
116
- throw new Error('Business not found');
117
- }
118
- if (!localClient) {
119
- throw new Error('Client not found');
120
- }
121
-
122
- // validate details
123
- const greenInvoiceCreatClientInput = convertLocalClientToGreenInvoiceCreateClientInput(
124
- localClient,
125
- localBusiness,
126
- );
127
-
128
- // add to green invoice
129
- const greenInvoiceClient = await injector
130
- .get(GreenInvoiceClientProvider)
131
- .createClient(greenInvoiceCreatClientInput);
132
-
133
- if (!greenInvoiceClient?.id) {
134
- throw new Error('Failed to create Green Invoice client');
135
- }
136
-
137
- // add green invoice id to local client
138
- await injector.get(ClientsProvider).updateClient({
139
- businessId: clientId,
140
- greenInvoiceId: greenInvoiceClient.id,
141
- });
142
- } catch (error) {
143
- console.error('Error adding Green Invoice client:', error);
144
- }
145
- }
146
-
147
- function pickGreenInvoiceClientFields(
148
- businessFields: Omit<UpdateBusinessInput, 'id'> & { name: string },
149
- clientFields: ClientUpdateInput,
150
- ): _DOLLAR_defs_updateClientRequest_Input {
151
- const fieldsToUpdate: _DOLLAR_defs_updateClientRequest_Input = {
152
- /** Phone number */
153
- phone: businessFields.phoneNumber,
154
- /** Mobile number */
155
- // mobile: businessFields.mobile_number,
156
- /** Email addresses */
157
- emails: clientFields.emails ? [...clientFields.emails] : undefined,
158
- /** Fax number */
159
- // fax: businessFields.fax_number,
160
- /** Contact person name */
161
- // contactPerson: businessFields.contact_person,
162
- /** Street address */
163
- address: businessFields.address ?? undefined,
164
- /** City name */
165
- // city: businessFields.city,
166
- /** Zip/postal code */
167
- // zip: businessFields.zip_code,
168
- country: businessFields.country
169
- ? countryCodeToGreenInvoiceCountry(businessFields.country as CountryCode)
170
- : undefined,
171
- /** Bank name */
172
- // bankName: businessFields.bank_name,
173
- /** Bank branch number */
174
- // bankBranch: businessFields.bank_branch_number,
175
- /** Bank account number */
176
- // bankAccount: businessFields.bank_account_number,
177
- /** The client name */
178
- name: businessFields.name ?? undefined,
179
- /** Is the client currently active or not */
180
- active: businessFields.isActive,
181
- /** The client tax ID */
182
- // taxId: businessFields.tax_id
183
- // paymentTerms: clientFields.payment_terms,
184
- // labels: clientFields.labels,
185
- /** Whether to send emails to the user automatically when assigning him to an invoice or not */
186
- // send: clientFields.send,
187
- /** The client department */
188
- // department: clientFields.department,
189
- /** The client accounting key */
190
- accountingKey: businessFields.sortCode?.toString(),
191
- /** The category this client is related to */
192
- // category: clientFields.category,
193
- /** The sub category this client is related to */
194
- // subCategory: clientFields.sub_category,
195
- /** Client remarks for self use */
196
- // remarks: clientFields.remarks,
197
- };
198
-
199
- return fieldsToUpdate;
200
- }
201
-
202
- export async function updateGreenInvoiceClient(
203
- clientId: string,
204
- injector: Injector,
205
- businessFields: UpdateBusinessInput = {},
206
- clientFields: ClientUpdateInput = {},
207
- ): Promise<void> {
208
- // validate local client
209
- const localBusinessPromise = injector
210
- .get(BusinessesProvider)
211
- .getBusinessByIdLoader.load(clientId);
212
- const localClientPromise = injector.get(ClientsProvider).getClientByIdLoader.load(clientId);
213
- const [localBusiness, localClient] = await Promise.all([
214
- localBusinessPromise,
215
- localClientPromise,
216
- ]);
217
- if (!localBusiness?.name || !localClient) {
218
- return;
219
- }
220
-
221
- const fieldsToUpdate = pickGreenInvoiceClientFields(
222
- { ...businessFields, name: localBusiness.name },
223
- clientFields,
224
- );
225
- if (Object.keys(fieldsToUpdate).length === 0) {
226
- return;
227
- }
228
-
229
- const greenInvoiceClient = await injector.get(GreenInvoiceClientProvider).updateClient({
230
- id: clientId,
231
- input: fieldsToUpdate,
232
- });
233
-
234
- if (!greenInvoiceClient?.id) {
235
- throw new Error('Failed to create Green Invoice client');
236
- }
237
-
238
- return;
239
- }