@bisondesk/core-sdk 1.0.676 → 1.0.677
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/lib/apis/exchange-rates.d.ts +3 -0
- package/lib/apis/exchange-rates.d.ts.map +1 -1
- package/lib/apis/exchange-rates.js +29 -0
- package/lib/apis/exchange-rates.js.map +1 -1
- package/lib/types/intercompany-payments.d.ts.map +1 -1
- package/lib/types/intercompany-payments.js.map +1 -1
- package/lib/types/offers.d.ts +2 -1
- package/lib/types/offers.d.ts.map +1 -1
- package/lib/types/offers.js.map +1 -1
- package/lib/types/opportunities.d.ts +9 -0
- package/lib/types/opportunities.d.ts.map +1 -1
- package/lib/types/opportunities.js.map +1 -1
- package/lib/types/opportunity-payments.d.ts +9 -0
- package/lib/types/opportunity-payments.d.ts.map +1 -1
- package/lib/types/opportunity-payments.js.map +1 -1
- package/lib/types/quote-settings.d.ts +1 -0
- package/lib/types/quote-settings.d.ts.map +1 -1
- package/lib/types/quote-settings.js.map +1 -1
- package/lib/types/quotes.d.ts +1 -0
- package/lib/types/quotes.d.ts.map +1 -1
- package/lib/types/quotes.js.map +1 -1
- package/lib/types/tenants.d.ts +1 -0
- package/lib/types/tenants.d.ts.map +1 -1
- package/lib/types/tenants.js.map +1 -1
- package/lib/types/vehicle-purchase-payments.d.ts +8 -1
- package/lib/types/vehicle-purchase-payments.d.ts.map +1 -1
- package/lib/types/vehicle-purchase-payments.js.map +1 -1
- package/lib/types/vehicles.d.ts +7 -0
- package/lib/types/vehicles.d.ts.map +1 -1
- package/lib/types/vehicles.js.map +1 -1
- package/lib/utils/opportunity-payments.d.ts +3 -0
- package/lib/utils/opportunity-payments.d.ts.map +1 -0
- package/lib/utils/opportunity-payments.js +5 -0
- package/lib/utils/opportunity-payments.js.map +1 -0
- package/lib/utils/opportunity-payments.test.d.ts +2 -0
- package/lib/utils/opportunity-payments.test.d.ts.map +1 -0
- package/lib/utils/opportunity-payments.test.js +23 -0
- package/lib/utils/opportunity-payments.test.js.map +1 -0
- package/lib/utils/tenants.d.ts +4 -0
- package/lib/utils/tenants.d.ts.map +1 -1
- package/lib/utils/tenants.js +8 -0
- package/lib/utils/tenants.js.map +1 -1
- package/lib/utils/tenants.test.js +44 -1
- package/lib/utils/tenants.test.js.map +1 -1
- package/package.json +1 -1
- package/src/apis/exchange-rates.ts +49 -0
- package/src/types/activities.js +13 -0
- package/src/types/activities.js.map +1 -0
- package/src/types/comparables.js +2 -0
- package/src/types/comparables.js.map +1 -0
- package/src/types/crm.js +58 -0
- package/src/types/crm.js.map +1 -0
- package/src/types/dashboard.js +2 -0
- package/src/types/dashboard.js.map +1 -0
- package/src/types/definitions.js +2 -0
- package/src/types/definitions.js.map +1 -0
- package/src/types/fields.js +2 -0
- package/src/types/fields.js.map +1 -0
- package/src/types/insights.js +2 -0
- package/src/types/insights.js.map +1 -0
- package/src/types/intercompany-payments.ts +4 -3
- package/src/types/interests.js +6 -0
- package/src/types/interests.js.map +1 -0
- package/src/types/internal-events.js +18 -0
- package/src/types/internal-events.js.map +1 -0
- package/src/types/internet-opportunities.js +2 -0
- package/src/types/internet-opportunities.js.map +1 -0
- package/src/types/internet-vehicles.js +2 -0
- package/src/types/internet-vehicles.js.map +1 -0
- package/src/types/leasing-administration.js +2 -0
- package/src/types/leasing-administration.js.map +1 -0
- package/src/types/leasing-debtors.js +2 -0
- package/src/types/leasing-debtors.js.map +1 -0
- package/src/types/leasing-search.js +2 -0
- package/src/types/leasing-search.js.map +1 -0
- package/src/types/leasing-settings.js +7 -0
- package/src/types/leasing-settings.js.map +1 -0
- package/src/types/leasing.js +38 -0
- package/src/types/leasing.js.map +1 -0
- package/src/types/marketing.js +35 -0
- package/src/types/marketing.js.map +1 -0
- package/src/types/offers.js +56 -0
- package/src/types/offers.ts +2 -0
- package/src/types/opportunities.js +107 -0
- package/src/types/opportunities.js.map +1 -0
- package/src/types/opportunities.ts +16 -0
- package/src/types/opportunity-payments.ts +23 -0
- package/src/types/payments.js +7 -0
- package/src/types/picklists.js +2 -0
- package/src/types/picklists.js.map +1 -0
- package/src/types/quote-settings.ts +2 -0
- package/src/types/quotes.js +42 -0
- package/src/types/quotes.ts +2 -0
- package/src/types/recently-viewed.js +2 -0
- package/src/types/recently-viewed.js.map +1 -0
- package/src/types/reservations.js +5 -0
- package/src/types/reservations.js.map +1 -0
- package/src/types/roi-ratings.js +5 -0
- package/src/types/roi-ratings.js.map +1 -0
- package/src/types/saved-filters.js +9 -0
- package/src/types/saved-filters.js.map +1 -0
- package/src/types/search.js +2 -0
- package/src/types/search.js.map +1 -0
- package/src/types/settings.js +2 -0
- package/src/types/settings.js.map +1 -0
- package/src/types/templates.js +2 -0
- package/src/types/templates.js.map +1 -0
- package/src/types/tenants.js +21 -0
- package/src/types/tenants.js.map +1 -0
- package/src/types/tenants.ts +6 -0
- package/src/types/user-performance.js +7 -0
- package/src/types/user-performance.js.map +1 -0
- package/src/types/utils.js +2 -0
- package/src/types/validation.js +2 -0
- package/src/types/validation.js.map +1 -0
- package/src/types/vehicle-purchase-payments.ts +16 -1
- package/src/types/vehicle-sales.js +6 -0
- package/src/types/vehicle-sales.js.map +1 -0
- package/src/types/vehicles.js +98 -0
- package/src/types/vehicles.js.map +1 -0
- package/src/types/vehicles.ts +15 -1
- package/src/utils/leasing.js +6 -0
- package/src/utils/leasing.js.map +1 -0
- package/src/utils/opportunities.js +48 -0
- package/src/utils/opportunities.js.map +1 -0
- package/src/utils/opportunity-payments.test.ts +31 -0
- package/src/utils/opportunity-payments.ts +15 -0
- package/src/utils/tenants.test.ts +60 -2
- package/src/utils/tenants.ts +28 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/types/vehicles.ts
CHANGED
|
@@ -170,6 +170,7 @@ export type NewVehicleRequest = {
|
|
|
170
170
|
dealStatus: VehiclePurchaseDealStatus;
|
|
171
171
|
costs: {
|
|
172
172
|
purchase: string;
|
|
173
|
+
foreign?: VehiclePurchaseDealForeign;
|
|
173
174
|
purchaseVatPercentage: string;
|
|
174
175
|
commission?: string;
|
|
175
176
|
externalTransport?: string;
|
|
@@ -811,6 +812,18 @@ export type VehiclePriceUpdateResponse =
|
|
|
811
812
|
errors: VehiclePriceUpdateError[];
|
|
812
813
|
};
|
|
813
814
|
|
|
815
|
+
/**
|
|
816
|
+
* The price the supplier asked, in the supplier's currency: one of the payment currencies of the
|
|
817
|
+
* vehicle's branch. The purchase's `deal.purchase` is then `purchase × exchangeRate`, and payments
|
|
818
|
+
* are authorized in `currencyCode`.
|
|
819
|
+
*/
|
|
820
|
+
export type VehiclePurchaseDealForeign = {
|
|
821
|
+
purchase: string; // exclusive VAT
|
|
822
|
+
currencyCode: string;
|
|
823
|
+
/** Branch currency units per 1 unit of `currencyCode`. */
|
|
824
|
+
exchangeRate: string;
|
|
825
|
+
};
|
|
826
|
+
|
|
814
827
|
export type VehiclePurchase = {
|
|
815
828
|
organizationId: string;
|
|
816
829
|
contactId: string;
|
|
@@ -851,7 +864,8 @@ export type VehiclePurchase = {
|
|
|
851
864
|
readyToDeliver?: boolean;
|
|
852
865
|
|
|
853
866
|
purchaseVatRate?: string;
|
|
854
|
-
purchase?: string; // exclusive VAT
|
|
867
|
+
purchase?: string; // exclusive VAT; derived from `foreign` when present
|
|
868
|
+
foreign?: VehiclePurchaseDealForeign;
|
|
855
869
|
|
|
856
870
|
bonus?: string; // sometimes manufacturers pay us a bonus when we reach a target
|
|
857
871
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UTCDate } from '@date-fns/utc';
|
|
2
|
+
import { format } from 'date-fns';
|
|
3
|
+
import { last, map, sortBy, uniqBy } from 'lodash-es';
|
|
4
|
+
export const sortContractClients = (clients) => sortBy(map(uniqBy(clients, (c) => c.takeoverId), (c) => ({ ...c, since: format(new UTCDate(c.since), 'yyyy-MM-dd') })), (cli) => cli.since, (cli) => (cli.takeoverId ? parseInt(cli.takeoverId.replace(/[^0-9]/g, '')) : 0));
|
|
5
|
+
export const getDealRef = ({ conditions, opportunities, }) => last(conditions) ?? last(opportunities);
|
|
6
|
+
//# sourceMappingURL=leasing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leasing.js","sourceRoot":"","sources":["leasing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAStD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAgC,EAA2B,EAAE,CAC/F,MAAM,CACJ,GAAG,CACD,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EACpC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CACrE,EACD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAClB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAChF,CAAC;AAEJ,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,UAAU,EACV,aAAa,GACyC,EAAkC,EAAE,CAC1F,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,aAAa,CAAE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { OpportunityStatus, OpportunityStatusOrder } from '../types/opportunities.js';
|
|
2
|
+
const compareOpportunityStatus = (input) => {
|
|
3
|
+
const { currentStatus, referenceStatus } = input;
|
|
4
|
+
const currentStatusIdx = OpportunityStatusOrder.indexOf(currentStatus);
|
|
5
|
+
const referenceStatusIdx = OpportunityStatusOrder.indexOf(referenceStatus);
|
|
6
|
+
return {
|
|
7
|
+
currentStatusIdx,
|
|
8
|
+
referenceStatusIdx,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export const getPreviousStatus = (currentStatus) => {
|
|
12
|
+
const currentIndex = OpportunityStatusOrder.indexOf(currentStatus);
|
|
13
|
+
if (currentIndex === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return OpportunityStatusOrder[currentIndex - 1];
|
|
17
|
+
};
|
|
18
|
+
export const getNextStatus = (status) => {
|
|
19
|
+
const statusIndex = OpportunityStatusOrder.indexOf(status);
|
|
20
|
+
if (statusIndex >= OpportunityStatusOrder.length - 1) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return OpportunityStatusOrder[statusIndex + 1];
|
|
24
|
+
};
|
|
25
|
+
export const isSameOrAfterReferenceOpportunityStatus = (input) => {
|
|
26
|
+
const { currentStatusIdx, referenceStatusIdx } = compareOpportunityStatus(input);
|
|
27
|
+
return currentStatusIdx >= referenceStatusIdx;
|
|
28
|
+
};
|
|
29
|
+
export const isAfterReferenceOpportunityStatus = (input) => {
|
|
30
|
+
const { currentStatusIdx, referenceStatusIdx } = compareOpportunityStatus(input);
|
|
31
|
+
return currentStatusIdx > referenceStatusIdx;
|
|
32
|
+
};
|
|
33
|
+
export const isSameOrBeforeReferenceOpportunityStatus = (input) => {
|
|
34
|
+
const { currentStatusIdx, referenceStatusIdx } = compareOpportunityStatus(input);
|
|
35
|
+
return currentStatusIdx <= referenceStatusIdx;
|
|
36
|
+
};
|
|
37
|
+
export const isBeforeReferenceOpportunityStatus = (input) => {
|
|
38
|
+
const { currentStatusIdx, referenceStatusIdx } = compareOpportunityStatus(input);
|
|
39
|
+
return currentStatusIdx < referenceStatusIdx;
|
|
40
|
+
};
|
|
41
|
+
export const isOpportunityLost = (input) => input.lostAt != null;
|
|
42
|
+
export const getOpportunityReservedStatus = () => [
|
|
43
|
+
OpportunityStatus.REVIEW,
|
|
44
|
+
OpportunityStatus.PREPARATION,
|
|
45
|
+
OpportunityStatus.DELIVERY,
|
|
46
|
+
];
|
|
47
|
+
export const isOpportunityReserved = (input) => getOpportunityReservedStatus().includes(input.status);
|
|
48
|
+
//# sourceMappingURL=opportunities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opportunities.js","sourceRoot":"","sources":["opportunities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAOnG,MAAM,wBAAwB,GAAG,CAAC,KAAmB,EAAE,EAAE;IACvD,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IAEjD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACvE,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAE3E,OAAO;QACL,gBAAgB;QAChB,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,aAAgC,EACD,EAAE;IACjC,MAAM,YAAY,GAAG,sBAAsB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACnE,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IACD,OAAO,sBAAsB,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAyB,EAAiC,EAAE;IACxF,MAAM,WAAW,GAAG,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,WAAW,IAAI,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrD,OAAO;IACT,CAAC;IACD,OAAO,sBAAsB,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,KAAmB,EAAW,EAAE;IACtF,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAEjF,OAAO,gBAAgB,IAAI,kBAAkB,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,KAAmB,EAAW,EAAE;IAChF,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAEjF,OAAO,gBAAgB,GAAG,kBAAkB,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,KAAmB,EAAW,EAAE;IACvF,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAEjF,OAAO,gBAAgB,IAAI,kBAAkB,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,KAAmB,EAAW,EAAE;IACjF,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAEjF,OAAO,gBAAgB,GAAG,kBAAkB,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAkB,EAAW,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC;AAEvF,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAwB,EAAE,CAAC;IACrE,iBAAiB,CAAC,MAAM;IACxB,iBAAiB,CAAC,WAAW;IAC7B,iBAAiB,CAAC,QAAQ;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAkB,EAAW,EAAE,CACnE,4BAA4B,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OpportunityPayment } from '../types/opportunity-payments.js';
|
|
2
|
+
import { isPaidInAlternativeCurrency } from './opportunity-payments.js';
|
|
3
|
+
|
|
4
|
+
const dollarPayment: Pick<OpportunityPayment, 'foreign' | 'deletedAt'> = {
|
|
5
|
+
foreign: { amount: '30000', currencyCode: 'USD', exchangeRate: '0.861804' },
|
|
6
|
+
};
|
|
7
|
+
const euroPayment: Pick<OpportunityPayment, 'foreign' | 'deletedAt'> = {};
|
|
8
|
+
|
|
9
|
+
describe('isPaidInAlternativeCurrency', () => {
|
|
10
|
+
it('shows the alternative currency before any payment arrived', () => {
|
|
11
|
+
expect(isPaidInAlternativeCurrency('USD', [])).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('shows the alternative currency while every payment arrived in it', () => {
|
|
15
|
+
expect(isPaidInAlternativeCurrency('USD', [dollarPayment, dollarPayment])).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('switches to branch currency once one payment arrived in branch currency', () => {
|
|
19
|
+
expect(isPaidInAlternativeCurrency('USD', [dollarPayment, euroPayment])).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('leaves deleted payments out', () => {
|
|
23
|
+
expect(
|
|
24
|
+
isPaidInAlternativeCurrency('USD', [dollarPayment, { deletedAt: '2026-09-30T10:00:00Z' }]),
|
|
25
|
+
).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('shows branch currency when the quote has no alternative currency', () => {
|
|
29
|
+
expect(isPaidInAlternativeCurrency(undefined, [dollarPayment])).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OpportunityPayment } from '../types/opportunity-payments.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a deal's payments are shown in the quote's alternative currency: every payment so far
|
|
5
|
+
* arrived in it. One payment in branch currency switches the deal to branch currency, because
|
|
6
|
+
* only the branch currency amounts then add up to the whole.
|
|
7
|
+
*/
|
|
8
|
+
export const isPaidInAlternativeCurrency = (
|
|
9
|
+
alternativeCurrency: string | undefined,
|
|
10
|
+
payments: Pick<OpportunityPayment, 'foreign' | 'deletedAt'>[],
|
|
11
|
+
): boolean =>
|
|
12
|
+
alternativeCurrency != null &&
|
|
13
|
+
payments
|
|
14
|
+
.filter((payment) => payment.deletedAt == null)
|
|
15
|
+
.every((payment) => payment.foreign?.currencyCode === alternativeCurrency);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { Branch } from '../types/tenants.js';
|
|
2
|
-
import {
|
|
1
|
+
import { Branch, Tenant } from '../types/tenants.js';
|
|
2
|
+
import {
|
|
3
|
+
areBranchesQuoteCompatible,
|
|
4
|
+
getBranchAskingVies,
|
|
5
|
+
getBranchPaymentCurrencies,
|
|
6
|
+
hasForeignPaymentCurrency,
|
|
7
|
+
isForeignPaymentCurrency,
|
|
8
|
+
} from './tenants.js';
|
|
3
9
|
|
|
4
10
|
const createBranch = (override?: Partial<Branch>): Branch => ({
|
|
5
11
|
id: 'TTC',
|
|
@@ -45,3 +51,55 @@ describe('areBranchesQuoteCompatible', () => {
|
|
|
45
51
|
expect(areBranchesQuoteCompatible(implicit, explicit)).toBe(true);
|
|
46
52
|
});
|
|
47
53
|
});
|
|
54
|
+
|
|
55
|
+
describe('getBranchAskingVies', () => {
|
|
56
|
+
const bolivia = createBranch({ id: 'BO', country: 'bo', vatNumber: '387032026' });
|
|
57
|
+
const belgium = createBranch({ id: 'BE', country: 'be', vatNumber: 'BE0405567886' });
|
|
58
|
+
const france = createBranch({ id: 'FR', country: 'fr', vatNumber: 'FR10821739638' });
|
|
59
|
+
const tenantOf = (branches: Branch[]) => ({ branches }) as Tenant;
|
|
60
|
+
|
|
61
|
+
test.each([
|
|
62
|
+
['the European branch the check is made for', 'FR', 'FR'],
|
|
63
|
+
['the first European branch when no branch is given', undefined, 'BE'],
|
|
64
|
+
['the first European branch when the given branch is outside the EU', 'BO', 'BE'],
|
|
65
|
+
['the first European branch when the given branch is unknown', 'GONE', 'BE'],
|
|
66
|
+
])('picks %s', (_label, branchId, expected) => {
|
|
67
|
+
expect(getBranchAskingVies(tenantOf([bolivia, belgium, france]), branchId)?.id).toBe(expected);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('asks anonymously for a tenant without a European branch', () => {
|
|
71
|
+
expect(getBranchAskingVies(tenantOf([bolivia]), 'BO')).toBeUndefined();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('payment currencies of a branch', () => {
|
|
76
|
+
const southAmerica = createBranch({
|
|
77
|
+
id: 'HPA South America',
|
|
78
|
+
paymentCurrencies: ['EUR', 'USD'],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('a branch without a list is paid in its own currency only', () => {
|
|
82
|
+
expect(getBranchPaymentCurrencies(createBranch())).toEqual(['EUR']);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('a branch with a list is paid in the currencies it lists', () => {
|
|
86
|
+
expect(getBranchPaymentCurrencies(southAmerica)).toEqual(['EUR', 'USD']);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test.each([
|
|
90
|
+
['a listed currency other than its own', 'USD', true],
|
|
91
|
+
['its own currency', 'EUR', false],
|
|
92
|
+
['a currency it does not list', 'BOB', false],
|
|
93
|
+
])('%s is a foreign payment currency: %s', (_label, currencyCode, expected) => {
|
|
94
|
+
expect(isForeignPaymentCurrency(southAmerica, currencyCode)).toBe(expected);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('a branch without a list has no foreign payment currency', () => {
|
|
98
|
+
expect(isForeignPaymentCurrency(createBranch(), 'USD')).toBe(false);
|
|
99
|
+
expect(hasForeignPaymentCurrency(createBranch())).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('a branch listing another currency has a foreign payment currency', () => {
|
|
103
|
+
expect(hasForeignPaymentCurrency(southAmerica)).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
});
|
package/src/utils/tenants.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { XError } from '@bisondesk/commons-sdk/errors';
|
|
2
|
+
import { isEUCountry } from '@bisondesk/commons-sdk/locations';
|
|
2
3
|
import { first } from 'lodash-es';
|
|
3
4
|
import { Branch, Tenant } from '../types/tenants.js';
|
|
4
5
|
|
|
@@ -13,6 +14,33 @@ export const getBranch = (tenant: Tenant, branchId: string): Branch => {
|
|
|
13
14
|
|
|
14
15
|
export const getDefaultBranch = (tenant: Tenant): Branch => first(tenant.branches)!;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The branch whose VAT number VIES records as the requester of a VAT check, which earns a
|
|
19
|
+
* consultation number: the branch the check is made for when it is European, else the tenant's
|
|
20
|
+
* first European branch. A tenant without a European branch asks VIES anonymously.
|
|
21
|
+
*/
|
|
22
|
+
export const getBranchAskingVies = (tenant: Tenant, branchId?: string): Branch | undefined => {
|
|
23
|
+
const europeanBranches = tenant.branches.filter((branch) => isEUCountry(branch.country));
|
|
24
|
+
return europeanBranches.find((branch) => branch.id === branchId) ?? europeanBranches.at(0);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The currencies money moves in at the branch, its own currency included. */
|
|
28
|
+
export const getBranchPaymentCurrencies = (branch: Branch): string[] =>
|
|
29
|
+
branch.paymentCurrencies ?? [branch.currency];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether the branch can be paid, price a purchase or receive a supplier invoice in a currency
|
|
33
|
+
* other than its own. Its own currency is never a foreign one.
|
|
34
|
+
*/
|
|
35
|
+
export const isForeignPaymentCurrency = (branch: Branch, currencyCode: string): boolean =>
|
|
36
|
+
currencyCode !== branch.currency && getBranchPaymentCurrencies(branch).includes(currencyCode);
|
|
37
|
+
|
|
38
|
+
/** Whether the branch lists any payment currency other than its own. */
|
|
39
|
+
export const hasForeignPaymentCurrency = (branch: Branch): boolean =>
|
|
40
|
+
getBranchPaymentCurrencies(branch).some((currencyCode) =>
|
|
41
|
+
isForeignPaymentCurrency(branch, currencyCode),
|
|
42
|
+
);
|
|
43
|
+
|
|
16
44
|
/** The source invoices the end customer directly; this branch collects payment and earns
|
|
17
45
|
* commission (see {@link Branch.dropshipping}). */
|
|
18
46
|
export const isDropshippingBranch = (branch: Branch): boolean => branch.dropshipping === true;
|