@accounter/server 0.0.8-alpha-20251105181339-4ce756e457f7145a4035565e526bc02285ab2675 → 0.0.8-alpha-20251105183654-b3147b83bfda6ce62d09073ce81342ceadf5160c
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.
- package/CHANGELOG.md +25 -5
- package/dist/server/src/__generated__/types.d.ts +39 -10
- package/dist/server/src/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/financial-entities/__generated__/clients.types.d.ts +11 -4
- package/dist/server/src/modules/financial-entities/__generated__/types.d.ts +19 -7
- package/dist/server/src/modules/financial-entities/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/financial-entities/helpers/clients.helper.d.ts +11 -0
- package/dist/server/src/modules/financial-entities/helpers/clients.helper.js +26 -0
- package/dist/server/src/modules/financial-entities/helpers/clients.helper.js.map +1 -0
- package/dist/server/src/modules/financial-entities/providers/businesses.provider.js +1 -1
- package/dist/server/src/modules/financial-entities/providers/clients.provider.js +18 -16
- package/dist/server/src/modules/financial-entities/providers/clients.provider.js.map +1 -1
- package/dist/server/src/modules/financial-entities/resolvers/clients.resolvers.js +26 -24
- package/dist/server/src/modules/financial-entities/resolvers/clients.resolvers.js.map +1 -1
- package/dist/server/src/modules/financial-entities/typeDefs/clients.graphql.js +24 -8
- package/dist/server/src/modules/financial-entities/typeDefs/clients.graphql.js.map +1 -1
- package/dist/server/src/modules/green-invoice/__generated__/types.d.ts +8 -0
- package/dist/server/src/modules/green-invoice/__generated__/types.js.map +1 -1
- package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.d.ts +3 -1
- package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js +5 -12
- package/dist/server/src/modules/green-invoice/helpers/contract-to-draft.helper.js.map +1 -1
- package/dist/server/src/modules/green-invoice/helpers/green-invoice-clients.helper.d.ts +1 -2
- package/dist/server/src/modules/green-invoice/helpers/green-invoice-clients.helper.js +17 -31
- package/dist/server/src/modules/green-invoice/helpers/green-invoice-clients.helper.js.map +1 -1
- package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.d.ts +2 -2
- package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js +16 -14
- package/dist/server/src/modules/green-invoice/helpers/green-invoice.helper.js.map +1 -1
- package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js +91 -29
- package/dist/server/src/modules/green-invoice/resolvers/green-invoice.resolvers.js.map +1 -1
- package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js +4 -0
- package/dist/server/src/modules/green-invoice/typeDefs/green-invoice.graphql.js.map +1 -1
- package/package.json +3 -4
- package/src/__generated__/types.ts +42 -10
- package/src/modules/financial-entities/__generated__/clients.types.ts +10 -4
- package/src/modules/financial-entities/__generated__/types.ts +19 -7
- package/src/modules/financial-entities/helpers/clients.helper.ts +28 -0
- package/src/modules/financial-entities/providers/businesses.provider.ts +1 -1
- package/src/modules/financial-entities/providers/clients.provider.ts +19 -16
- package/src/modules/financial-entities/resolvers/clients.resolvers.ts +30 -27
- package/src/modules/financial-entities/typeDefs/clients.graphql.ts +24 -8
- package/src/modules/green-invoice/__generated__/types.ts +8 -0
- package/src/modules/green-invoice/helpers/contract-to-draft.helper.ts +7 -13
- package/src/modules/green-invoice/helpers/green-invoice-clients.helper.ts +19 -40
- package/src/modules/green-invoice/helpers/green-invoice.helper.ts +17 -18
- package/src/modules/green-invoice/resolvers/green-invoice.resolvers.ts +101 -35
- package/src/modules/green-invoice/typeDefs/green-invoice.graphql.ts +4 -0
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
IInsertDocumentsResult,
|
|
15
15
|
IUpdateIssuedDocumentParams,
|
|
16
16
|
} from '@modules/documents/types.js';
|
|
17
|
+
import { validateClientIntegrations } from '@modules/financial-entities/helpers/clients.helper.js';
|
|
17
18
|
import { BusinessesProvider } from '@modules/financial-entities/providers/businesses.provider.js';
|
|
18
19
|
import { ClientsProvider } from '@modules/financial-entities/providers/clients.provider.js';
|
|
19
20
|
import {
|
|
@@ -27,10 +28,9 @@ import {
|
|
|
27
28
|
} from '@modules/green-invoice/helpers/green-invoice.helper.js';
|
|
28
29
|
import { TransactionsProvider } from '@modules/transactions/providers/transactions.provider.js';
|
|
29
30
|
import { Currency, DocumentType } from '@shared/enums';
|
|
30
|
-
import {
|
|
31
|
+
import { BillingCycle, ResolversTypes } from '@shared/gql-types';
|
|
31
32
|
import { dateToTimelessDateString } from '@shared/helpers';
|
|
32
33
|
import { convertContractToDraft } from '../helpers/contract-to-draft.helper.js';
|
|
33
|
-
import { getClientFromGreenInvoiceClient } from '../helpers/green-invoice-clients.helper.js';
|
|
34
34
|
import {
|
|
35
35
|
deduceVatTypeFromBusiness,
|
|
36
36
|
executeDocumentIssue,
|
|
@@ -105,18 +105,13 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
105
105
|
}) as IGetIssuedDocumentsByIdsResult[],
|
|
106
106
|
);
|
|
107
107
|
|
|
108
|
-
const clientPromise = charge.business_id
|
|
109
|
-
? getClientFromGreenInvoiceClient(injector, charge.business_id)
|
|
110
|
-
: Promise.resolve(undefined);
|
|
111
|
-
|
|
112
108
|
const paymentPromise = getPaymentsFromTransactions(injector, transactions);
|
|
113
109
|
|
|
114
110
|
const vatTypePromise = deduceVatTypeFromBusiness(injector, locality, charge.business_id);
|
|
115
111
|
|
|
116
|
-
const [businessMatch, openIssuedDocuments,
|
|
112
|
+
const [businessMatch, openIssuedDocuments, payment, vatType] = await Promise.all([
|
|
117
113
|
businessMatchPromise,
|
|
118
114
|
openIssuedDocumentsPromise,
|
|
119
|
-
clientPromise,
|
|
120
115
|
paymentPromise,
|
|
121
116
|
vatTypePromise,
|
|
122
117
|
]);
|
|
@@ -136,6 +131,10 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
136
131
|
),
|
|
137
132
|
).then(res => res.filter(Boolean) as _DOLLAR_defs_Document[]);
|
|
138
133
|
|
|
134
|
+
const greenInvoiceClientId = validateClientIntegrations(
|
|
135
|
+
businessMatch?.integrations ?? {},
|
|
136
|
+
).greenInvoiceId;
|
|
137
|
+
|
|
139
138
|
const income = getIncomeFromDocuments(
|
|
140
139
|
openIssuedDocuments.map(doc => ({
|
|
141
140
|
document: documents.find(d => d.id === doc.id)!,
|
|
@@ -193,7 +192,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
193
192
|
vatType,
|
|
194
193
|
rounding: false,
|
|
195
194
|
signed: true,
|
|
196
|
-
client,
|
|
195
|
+
client: greenInvoiceClientId,
|
|
197
196
|
income,
|
|
198
197
|
payment,
|
|
199
198
|
// linkedPaymentId: ____,
|
|
@@ -284,14 +283,13 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
284
283
|
|
|
285
284
|
const paymentPromise = getPaymentsFromTransactions(injector, transactions ?? []);
|
|
286
285
|
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
286
|
+
const greenInvoiceClientId = validateClientIntegrations(
|
|
287
|
+
businessMatch?.integrations ?? {},
|
|
288
|
+
).greenInvoiceId;
|
|
290
289
|
|
|
291
|
-
const [greenInvoiceDocument, payment
|
|
290
|
+
const [greenInvoiceDocument, payment] = await Promise.all([
|
|
292
291
|
greenInvoiceDocumentPromise,
|
|
293
292
|
paymentPromise,
|
|
294
|
-
clientPromise,
|
|
295
293
|
]);
|
|
296
294
|
|
|
297
295
|
if (!greenInvoiceDocument) {
|
|
@@ -341,7 +339,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
341
339
|
vatType,
|
|
342
340
|
rounding: false,
|
|
343
341
|
signed: true,
|
|
344
|
-
client,
|
|
342
|
+
client: greenInvoiceClientId,
|
|
345
343
|
income,
|
|
346
344
|
payment,
|
|
347
345
|
// linkedPaymentId: ____,
|
|
@@ -352,8 +350,9 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
352
350
|
},
|
|
353
351
|
clientMonthlyChargesDrafts: async (_, { issueMonth }, { injector }) => {
|
|
354
352
|
const openContracts = await injector.get(ContractsProvider).getAllOpenContracts();
|
|
353
|
+
const monthlyBillingCycle: BillingCycle = 'MONTHLY';
|
|
355
354
|
const monthlyContracts = openContracts.filter(
|
|
356
|
-
contract => contract.billing_cycle ===
|
|
355
|
+
contract => contract.billing_cycle.toLocaleUpperCase() === monthlyBillingCycle,
|
|
357
356
|
);
|
|
358
357
|
const drafts = await Promise.all(
|
|
359
358
|
monthlyContracts.map(async contract =>
|
|
@@ -389,15 +388,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
389
388
|
const clientPromise = injector
|
|
390
389
|
.get(ClientsProvider)
|
|
391
390
|
.getClientByIdLoader.load(contract.client_id);
|
|
392
|
-
const
|
|
393
|
-
injector,
|
|
394
|
-
contract.client_id,
|
|
395
|
-
);
|
|
396
|
-
const [business, client, greenInvoiceClient] = await Promise.all([
|
|
397
|
-
businessPromise,
|
|
398
|
-
clientPromise,
|
|
399
|
-
greenInvoiceClientPromise,
|
|
400
|
-
]);
|
|
391
|
+
const [business, client] = await Promise.all([businessPromise, clientPromise]);
|
|
401
392
|
|
|
402
393
|
if (!business) {
|
|
403
394
|
throw new GraphQLError(`Business ID="${contract.client_id}" not found`);
|
|
@@ -407,7 +398,9 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
407
398
|
throw new GraphQLError(`Client not found for business ID="${contract.client_id}"`);
|
|
408
399
|
}
|
|
409
400
|
|
|
410
|
-
|
|
401
|
+
const greenInvoiceId = validateClientIntegrations(client.integrations)?.greenInvoiceId;
|
|
402
|
+
|
|
403
|
+
if (!greenInvoiceId) {
|
|
411
404
|
throw new GraphQLError(
|
|
412
405
|
`Green invoice match not found for business ID="${contract.client_id}"`,
|
|
413
406
|
);
|
|
@@ -419,7 +412,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
419
412
|
const year = today.getFullYear() + (today.getMonth() === 0 ? -1 : 0);
|
|
420
413
|
const month = format(subMonths(today, 1), 'MMMM');
|
|
421
414
|
|
|
422
|
-
const draft: NewDocumentInfo = {
|
|
415
|
+
const draft: ResolversTypes['NewDocumentInfo'] = {
|
|
423
416
|
remarks: `${contract.purchase_orders[0] ? `PO: ${contract.purchase_orders[0]}${contract.remarks ? ', ' : ''}` : ''}${contract.remarks ?? ''}`,
|
|
424
417
|
description: `GraphQL Hive Enterprise License - ${month} ${year}`,
|
|
425
418
|
type: normalizeDocumentType(contract.document_type),
|
|
@@ -430,10 +423,7 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
430
423
|
vatType: 'EXEMPT',
|
|
431
424
|
rounding: false,
|
|
432
425
|
signed: true,
|
|
433
|
-
client:
|
|
434
|
-
...greenInvoiceClient,
|
|
435
|
-
emails: [...((client.emails?.filter(Boolean) as string[]) ?? [])],
|
|
436
|
-
},
|
|
426
|
+
client: greenInvoiceId,
|
|
437
427
|
income: [
|
|
438
428
|
{
|
|
439
429
|
description: `GraphQL Hive Enterprise License - ${month} ${year}`,
|
|
@@ -454,12 +444,12 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
454
444
|
throw new GraphQLError(`Client not found for ID="${clientId}"`);
|
|
455
445
|
}
|
|
456
446
|
|
|
457
|
-
const
|
|
458
|
-
if (!
|
|
459
|
-
throw new GraphQLError(`
|
|
447
|
+
const greenInvoiceId = validateClientIntegrations(client.integrations)?.greenInvoiceId;
|
|
448
|
+
if (!greenInvoiceId) {
|
|
449
|
+
throw new GraphQLError(`Client ID="${clientId}" is missing Green Invoice integration`);
|
|
460
450
|
}
|
|
461
451
|
|
|
462
|
-
return
|
|
452
|
+
return greenInvoiceId;
|
|
463
453
|
} catch (error) {
|
|
464
454
|
const message = 'Failed to fetch Green Invoice client';
|
|
465
455
|
console.error(message, error);
|
|
@@ -658,4 +648,80 @@ export const greenInvoiceResolvers: GreenInvoiceModule.Resolvers = {
|
|
|
658
648
|
}
|
|
659
649
|
},
|
|
660
650
|
},
|
|
651
|
+
ClientIntegrations: {
|
|
652
|
+
greenInvoiceInfo: business =>
|
|
653
|
+
validateClientIntegrations(business.integrations).greenInvoiceId ?? null,
|
|
654
|
+
},
|
|
655
|
+
GreenInvoiceClient: {
|
|
656
|
+
id: clientId => clientId,
|
|
657
|
+
country: async (clientId, _, { injector }) => {
|
|
658
|
+
return injector
|
|
659
|
+
.get(GreenInvoiceClientProvider)
|
|
660
|
+
.clientLoader.load(clientId)
|
|
661
|
+
.then(client => {
|
|
662
|
+
if (client?.country) {
|
|
663
|
+
// TODO: use Country for server responses
|
|
664
|
+
// greenInvoiceCountryToCountryCode(client.country)
|
|
665
|
+
return client.country;
|
|
666
|
+
}
|
|
667
|
+
return null;
|
|
668
|
+
});
|
|
669
|
+
},
|
|
670
|
+
emails: async (clientId, _, { injector }) => {
|
|
671
|
+
const emails = await injector
|
|
672
|
+
.get(GreenInvoiceClientProvider)
|
|
673
|
+
.clientLoader.load(clientId)
|
|
674
|
+
.then(client => client?.emails);
|
|
675
|
+
|
|
676
|
+
return [...((emails?.filter(Boolean) as string[]) ?? []), 'ap@the-guild.dev']; // TODO: remove hardcoded email
|
|
677
|
+
},
|
|
678
|
+
name: async (clientId, _, { injector }) => {
|
|
679
|
+
return injector
|
|
680
|
+
.get(GreenInvoiceClientProvider)
|
|
681
|
+
.clientLoader.load(clientId)
|
|
682
|
+
.then(client => client?.name ?? null);
|
|
683
|
+
},
|
|
684
|
+
phone: async (clientId, _, { injector }) => {
|
|
685
|
+
return injector
|
|
686
|
+
.get(GreenInvoiceClientProvider)
|
|
687
|
+
.clientLoader.load(clientId)
|
|
688
|
+
.then(client => client?.phone ?? null);
|
|
689
|
+
},
|
|
690
|
+
taxId: async (clientId, _, { injector }) => {
|
|
691
|
+
return injector
|
|
692
|
+
.get(GreenInvoiceClientProvider)
|
|
693
|
+
.clientLoader.load(clientId)
|
|
694
|
+
.then(client => client?.taxId ?? null);
|
|
695
|
+
},
|
|
696
|
+
address: async (clientId, _, { injector }) => {
|
|
697
|
+
return injector
|
|
698
|
+
.get(GreenInvoiceClientProvider)
|
|
699
|
+
.clientLoader.load(clientId)
|
|
700
|
+
.then(client => client?.address ?? null);
|
|
701
|
+
},
|
|
702
|
+
city: async (clientId, _, { injector }) => {
|
|
703
|
+
return injector
|
|
704
|
+
.get(GreenInvoiceClientProvider)
|
|
705
|
+
.clientLoader.load(clientId)
|
|
706
|
+
.then(client => client?.city ?? null);
|
|
707
|
+
},
|
|
708
|
+
zip: async (clientId, _, { injector }) => {
|
|
709
|
+
return injector
|
|
710
|
+
.get(GreenInvoiceClientProvider)
|
|
711
|
+
.clientLoader.load(clientId)
|
|
712
|
+
.then(client => client?.zip ?? null);
|
|
713
|
+
},
|
|
714
|
+
fax: async (clientId, _, { injector }) => {
|
|
715
|
+
return injector
|
|
716
|
+
.get(GreenInvoiceClientProvider)
|
|
717
|
+
.clientLoader.load(clientId)
|
|
718
|
+
.then(client => client?.fax ?? null);
|
|
719
|
+
},
|
|
720
|
+
mobile: async (clientId, _, { injector }) => {
|
|
721
|
+
return injector
|
|
722
|
+
.get(GreenInvoiceClientProvider)
|
|
723
|
+
.clientLoader.load(clientId)
|
|
724
|
+
.then(client => client?.mobile ?? null);
|
|
725
|
+
},
|
|
726
|
+
},
|
|
661
727
|
};
|
|
@@ -33,6 +33,10 @@ export default gql`
|
|
|
33
33
|
originalDocument: NewDocumentInfo
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
extend type ClientIntegrations {
|
|
37
|
+
greenInvoiceInfo: GreenInvoiceClient
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
" result type for generateMonthlyClientDocuments" # eslint-disable-next-line @graphql-eslint/strict-id-in-types -- no current solution for this
|
|
37
41
|
type GenerateMonthlyClientDocumentsResult {
|
|
38
42
|
success: Boolean!
|