@unimaze/billing 0.21.71 → 1.0.1

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 (34) hide show
  1. package/lib/common/components/customer/index.js +1 -1
  2. package/lib/common/components/input/index.d.ts +2 -0
  3. package/lib/common/components/input/index.js +6 -3
  4. package/lib/common/components/invoice-preview/InvoicePreviewCustomerSupplierInfoBox.d.ts +6 -0
  5. package/lib/common/components/invoice-preview/InvoicePreviewCustomerSupplierInfoBox.js +19 -1
  6. package/lib/common/components/invoice-preview/index.d.ts +23 -0
  7. package/lib/common/components/invoice-preview/index.js +17 -1
  8. package/lib/common/components/session-bar/index.d.ts +40 -0
  9. package/lib/common/components/session-bar/index.js +87 -0
  10. package/lib/common/components/supplier/CityAutofill.d.ts +2 -0
  11. package/lib/common/components/supplier/CityAutofill.js +4 -3
  12. package/lib/common/components/supplier/SendOnBehalfOf.d.ts +88 -0
  13. package/lib/common/components/supplier/SendOnBehalfOf.js +281 -0
  14. package/lib/common/components/supplier/index.d.ts +16 -0
  15. package/lib/common/components/supplier/index.js +69 -18
  16. package/lib/common/types/CommonProps.d.ts +16 -0
  17. package/lib/common/types/SellerSelection.d.ts +16 -0
  18. package/lib/common/types/SellerSelection.js +10 -0
  19. package/lib/create-invoice/IntlLoader.js +1 -1
  20. package/lib/create-invoice/index.d.ts +8 -0
  21. package/lib/create-invoice/index.js +121 -41
  22. package/lib/style/index.css +51 -0
  23. package/lib/translations/locales/en.json +24 -0
  24. package/lib/translations/locales/is.json +24 -0
  25. package/lib/translations/locales.d.ts +48 -0
  26. package/lib/utils/ApiUtility.d.ts +9 -2
  27. package/lib/utils/ApiUtility.js +30 -3
  28. package/lib/utils/ConversionUtility.d.ts +6 -2
  29. package/lib/utils/ConversionUtility.js +16 -14
  30. package/lib/utils/WizardSnapshotUtility.d.ts +20 -0
  31. package/lib/utils/WizardSnapshotUtility.js +88 -0
  32. package/package.json +2 -2
  33. package/lib/common/components/attachments/ListAttachments.d.ts +0 -10
  34. package/lib/common/components/attachments/ListAttachments.js +0 -143
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
37
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
38
+ if (ar || !(i in from)) {
39
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
40
+ ar[i] = from[i];
41
+ }
42
+ }
43
+ return to.concat(ar || Array.prototype.slice.call(from));
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.translationMessages = void 0;
47
+ var React = __importStar(require("react"));
48
+ var react_1 = require("react");
49
+ var antd_1 = require("antd");
50
+ var react_intl_1 = require("react-intl");
51
+ var ApiUtility_1 = require("../../../utils/ApiUtility");
52
+ var SellerSelection_1 = require("../../types/SellerSelection");
53
+ var ConversionUtility_1 = require("../../../utils/ConversionUtility");
54
+ exports.translationMessages = (0, react_intl_1.defineMessages)({
55
+ sendOnBehalf_title: {
56
+ id: "sendOnBehalf_title",
57
+ defaultMessage: "On whose behalf are you sending the invoice?",
58
+ },
59
+ sendOnBehalf_self: {
60
+ id: "sendOnBehalf_self",
61
+ defaultMessage: "Myself (sole trader / contractor)",
62
+ },
63
+ sendOnBehalf_company: {
64
+ id: "sendOnBehalf_company",
65
+ defaultMessage: "On behalf of a company",
66
+ },
67
+ sendOnBehalf_companyIdentifier: {
68
+ id: "sendOnBehalf_companyIdentifier",
69
+ defaultMessage: "Company registration number",
70
+ },
71
+ sendOnBehalf_lookup: {
72
+ id: "sendOnBehalf_lookup",
73
+ defaultMessage: "Look up",
74
+ },
75
+ sendOnBehalf_procuration: {
76
+ id: "sendOnBehalf_procuration",
77
+ defaultMessage: "Holder of procuration according to the company register",
78
+ },
79
+ sendOnBehalf_granted: {
80
+ id: "sendOnBehalf_granted",
81
+ defaultMessage: "You hold a power of attorney for this company",
82
+ },
83
+ sendOnBehalf_notAllowed: {
84
+ id: "sendOnBehalf_notAllowed",
85
+ defaultMessage: "You are neither a holder of procuration nor hold a power of attorney for {name}. Ask a holder of procuration to grant you one.",
86
+ },
87
+ sendOnBehalf_notFound: {
88
+ id: "sendOnBehalf_notFound",
89
+ defaultMessage: "The company was not found in the company register",
90
+ },
91
+ sendOnBehalf_selectCompany: {
92
+ id: "sendOnBehalf_selectCompany",
93
+ defaultMessage: "Select a company",
94
+ },
95
+ sendOnBehalf_otherCompany: {
96
+ id: "sendOnBehalf_otherCompany",
97
+ defaultMessage: "Enter another registration number…",
98
+ },
99
+ sendOnBehalf_procurationTag: {
100
+ id: "sendOnBehalf_procurationTag",
101
+ defaultMessage: "Procuration holder",
102
+ },
103
+ sendOnBehalf_grantedTag: {
104
+ id: "sendOnBehalf_grantedTag",
105
+ defaultMessage: "Power of attorney",
106
+ },
107
+ sendOnBehalf_lostTag: {
108
+ id: "sendOnBehalf_lostTag",
109
+ defaultMessage: "No longer authorised",
110
+ },
111
+ });
112
+ /** Select value for typing a registration number that is not in the person's list */
113
+ var OTHER_COMPANY = "__other";
114
+ var SendOnBehalfOf = function (props) {
115
+ var _a;
116
+ var initialCompany = props.initialSeller && !props.initialSeller.isSelf ? props.initialSeller.isoIdentifier : undefined;
117
+ var _b = (0, react_1.useState)(initialCompany ? "company" : "self"), mode = _b[0], setMode = _b[1];
118
+ var _c = (0, react_1.useState)([]), companies = _c[0], setCompanies = _c[1];
119
+ var _d = (0, react_1.useState)(initialCompany), selectedCompany = _d[0], setSelectedCompany = _d[1];
120
+ var _e = (0, react_1.useState)(""), companyKennitala = _e[0], setCompanyKennitala = _e[1];
121
+ var _f = (0, react_1.useState)(false), isLoading = _f[0], setIsLoading = _f[1];
122
+ var _g = (0, react_1.useState)(null), company = _g[0], setCompany = _g[1];
123
+ var _h = (0, react_1.useState)(undefined), errorMessage = _h[0], setErrorMessage = _h[1];
124
+ /** False after starting a re-login, so no call is made with an expired token */
125
+ var ensureSession = function () {
126
+ if (!props.isSessionExpiring())
127
+ return true;
128
+ props.onSessionExpired();
129
+ return false;
130
+ };
131
+ var loadCompanies = function () {
132
+ if (!ensureSession())
133
+ return;
134
+ (0, ApiUtility_1.getRepresentedCompanies)(props.rapiBaseUrl, props.accessToken)
135
+ .then(function (list) {
136
+ var _a;
137
+ setCompanies(list);
138
+ (_a = props.onRepresentedCompaniesChange) === null || _a === void 0 ? void 0 : _a.call(props, list);
139
+ })
140
+ .catch(function (error) {
141
+ if ((0, ApiUtility_1.isUnauthorized)(error))
142
+ props.onSessionExpired();
143
+ });
144
+ };
145
+ (0, react_1.useEffect)(function () {
146
+ loadCompanies();
147
+ if (initialCompany)
148
+ lookUpCompany(initialCompany);
149
+ // eslint-disable-next-line react-hooks/exhaustive-deps
150
+ }, []);
151
+ (0, react_1.useEffect)(function () {
152
+ if (mode === "self") {
153
+ selectSelf();
154
+ }
155
+ else {
156
+ var seller = company && (0, SellerSelection_1.mayRepresent)(company.callerRoles)
157
+ ? company
158
+ : null;
159
+ var sellerSelection = company
160
+ ? toSelection(company)
161
+ : null;
162
+ props.onSellerChange(seller, sellerSelection);
163
+ }
164
+ // eslint-disable-next-line react-hooks/exhaustive-deps
165
+ }, [mode]);
166
+ var toSelection = function (entity) {
167
+ var _a, _b, _c;
168
+ return ({
169
+ isSelf: false,
170
+ isoIdentifier: (_a = entity.legalIdentifier) !== null && _a !== void 0 ? _a : "",
171
+ name: (_b = entity.name) !== null && _b !== void 0 ? _b : "",
172
+ roles: (_c = entity.callerRoles) !== null && _c !== void 0 ? _c : [],
173
+ });
174
+ };
175
+ /** Sole traders may be VAT registered under their own kennitala: use the register when it knows them */
176
+ var selectSelf = function () {
177
+ var selection = { isSelf: true, isoIdentifier: props.loggedInPerson.isoIdentifier, name: props.loggedInPerson.name, roles: [] };
178
+ var person = { legalIdentifier: props.loggedInPerson.isoIdentifier, name: props.loggedInPerson.name, vatNumbers: [] };
179
+ props.onSellerChange(person, selection);
180
+ if (!ensureSession())
181
+ return;
182
+ (0, ApiUtility_1.getBusinessEntity)(props.rapiBaseUrl, props.loggedInPerson.isoIdentifier, props.accessToken)
183
+ .then(function (response) { return props.onSellerChange(__assign(__assign({}, response.data), { name: props.loggedInPerson.name }), selection); })
184
+ .catch(function (error) {
185
+ // a person who is not in the company register keeps the name and kennitala from the login
186
+ if ((0, ApiUtility_1.isUnauthorized)(error))
187
+ props.onSessionExpired();
188
+ });
189
+ };
190
+ var lookUpCompany = function (isoIdentifier) {
191
+ if (!ensureSession())
192
+ return;
193
+ setIsLoading(true);
194
+ setErrorMessage(undefined);
195
+ (0, ApiUtility_1.getBusinessEntity)(props.rapiBaseUrl, isoIdentifier, props.accessToken)
196
+ .then(function (response) {
197
+ var entity = response.data;
198
+ setCompany(entity);
199
+ if ((0, SellerSelection_1.mayRepresent)(entity.callerRoles)) {
200
+ props.onSellerChange(entity, toSelection(entity));
201
+ }
202
+ else {
203
+ setErrorMessage(props.intl.formatMessage(exports.translationMessages.sendOnBehalf_notAllowed, { name: entity.name }));
204
+ props.onSellerChange(null, null);
205
+ }
206
+ })
207
+ .catch(function (error) {
208
+ setCompany(null);
209
+ props.onSellerChange(null, null);
210
+ if ((0, ApiUtility_1.isUnauthorized)(error))
211
+ props.onSessionExpired();
212
+ else
213
+ setErrorMessage(props.intl.formatMessage(exports.translationMessages.sendOnBehalf_notFound));
214
+ })
215
+ .finally(function () { return setIsLoading(false); });
216
+ };
217
+ var lookUpTypedKennitala = function () {
218
+ var digits = (0, ConversionUtility_1.stripToDigits)(companyKennitala);
219
+ if (digits.length === 10)
220
+ lookUpCompany((0, ConversionUtility_1.getIdentifierWithPrefix)(digits));
221
+ };
222
+ var onCompanySelected = function (value) {
223
+ setSelectedCompany(value);
224
+ setCompany(null);
225
+ setErrorMessage(undefined);
226
+ props.onSellerChange(null, null);
227
+ if (value !== OTHER_COMPANY)
228
+ lookUpCompany(value);
229
+ };
230
+ var roleTag = function (roles) {
231
+ if (!(0, SellerSelection_1.mayRepresent)(roles))
232
+ return React.createElement(antd_1.Tag, null, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_lostTag));
233
+ return roles.includes(SellerSelection_1.PROCURATION)
234
+ ? React.createElement(antd_1.Tag, { color: "green" }, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_procurationTag))
235
+ : React.createElement(antd_1.Tag, { color: "blue" }, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_grantedTag));
236
+ };
237
+ var companyOptions = __spreadArray(__spreadArray([], companies.map(function (c) {
238
+ var _a, _b;
239
+ return ({
240
+ value: (_a = c.legalIdentifier) !== null && _a !== void 0 ? _a : "",
241
+ // a company the person no longer represents is shown once, grayed out; Registry has already removed it
242
+ disabled: !(0, SellerSelection_1.mayRepresent)(c.callerRoles),
243
+ label: (React.createElement(antd_1.Flex, { justify: "space-between", align: "center", gap: "small" },
244
+ React.createElement("span", null,
245
+ c.name,
246
+ " (",
247
+ (0, ConversionUtility_1.getKennitalaFromIsoIdentifier)(c.legalIdentifier, { dashed: false }),
248
+ ")"),
249
+ roleTag((_b = c.callerRoles) !== null && _b !== void 0 ? _b : []))),
250
+ });
251
+ }), true), [
252
+ { value: OTHER_COMPANY, disabled: false, label: React.createElement("span", null, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_otherCompany)) },
253
+ ], false);
254
+ var isTypingKennitala = companies.length === 0 || selectedCompany === OTHER_COMPANY;
255
+ return (React.createElement(antd_1.Flex, { vertical: true, gap: "small", style: { background: "#FFF7E6", border: "1px solid #F59E0B", borderRadius: 8, padding: props.isMobile ? 12 : 18, marginBottom: 16 } },
256
+ React.createElement(antd_1.Typography.Text, { strong: true }, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_title)),
257
+ React.createElement(antd_1.Radio.Group, { value: mode, onChange: function (e) { return setMode(e.target.value); } },
258
+ React.createElement(antd_1.Flex, { vertical: props.isMobile, gap: props.isMobile ? 4 : 24 },
259
+ React.createElement(antd_1.Radio, { value: "self" }, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_self)),
260
+ React.createElement(antd_1.Radio, { value: "company" }, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_company)))),
261
+ mode === "self" && (React.createElement(antd_1.Typography.Text, null,
262
+ props.loggedInPerson.name,
263
+ " \u00B7 ",
264
+ (0, ConversionUtility_1.getKennitalaFromIsoIdentifier)(props.loggedInPerson.isoIdentifier, { dashed: false }))),
265
+ mode === "company" && (React.createElement(React.Fragment, null,
266
+ companies.length > 0 && (React.createElement(antd_1.Select, { value: selectedCompany, placeholder: props.intl.formatMessage(exports.translationMessages.sendOnBehalf_selectCompany), options: companyOptions, onChange: onCompanySelected, onDropdownVisibleChange: function (open) { return open && loadCompanies(); }, loading: isLoading, style: { maxWidth: props.isMobile ? undefined : 480 } })),
267
+ isTypingKennitala && (React.createElement(antd_1.Flex, { vertical: props.isMobile, gap: "small" },
268
+ React.createElement(antd_1.Input, { value: companyKennitala, placeholder: props.intl.formatMessage(exports.translationMessages.sendOnBehalf_companyIdentifier), maxLength: 11, onChange: function (e) { return setCompanyKennitala(e.target.value); }, onPressEnter: lookUpTypedKennitala, style: { maxWidth: props.isMobile ? undefined : 220 } }),
269
+ React.createElement(antd_1.Button, { onClick: lookUpTypedKennitala, loading: isLoading, disabled: (0, ConversionUtility_1.stripToDigits)(companyKennitala).length !== 10 }, props.intl.formatMessage(exports.translationMessages.sendOnBehalf_lookup)))),
270
+ company && (0, SellerSelection_1.mayRepresent)(company.callerRoles) && (React.createElement(antd_1.Typography.Text, null,
271
+ React.createElement("span", { style: { color: "#15803D" } }, "\u2713"),
272
+ " ",
273
+ React.createElement(antd_1.Typography.Text, { strong: true }, company.name),
274
+ " \u00B7",
275
+ " ",
276
+ props.intl.formatMessage(((_a = company.callerRoles) !== null && _a !== void 0 ? _a : []).includes(SellerSelection_1.PROCURATION)
277
+ ? exports.translationMessages.sendOnBehalf_procuration
278
+ : exports.translationMessages.sendOnBehalf_granted))),
279
+ errorMessage && React.createElement(antd_1.Alert, { type: "error", showIcon: true, message: errorMessage })))));
280
+ };
281
+ exports.default = (0, react_intl_1.injectIntl)(SendOnBehalfOf);
@@ -2,6 +2,9 @@ import * as React from "react";
2
2
  import { WrappedComponentProps } from "react-intl";
3
3
  import { NewReceiverRequirements } from "../../types/NewReceiverRequirements";
4
4
  import { FormInstance } from "antd/lib/form";
5
+ import { BusinessEntityCollectionResource } from "@unimaze/api-clients/lib/rapi";
6
+ import { SellerSelection } from "../../types/SellerSelection";
7
+ import { LoggedInPerson } from "../../types/CommonProps";
5
8
  export declare const translationMessages: {
6
9
  supplier_title: {
7
10
  id: string;
@@ -91,6 +94,19 @@ interface Props extends WrappedComponentProps {
91
94
  onSaveFieldValues: (fields: any) => void;
92
95
  isSaveFieldValuesSelected: boolean;
93
96
  onSaveFieldValuesChange: () => void;
97
+ /** Set when the portal requires login: the seller then comes from the "On behalf of" banner */
98
+ accessToken?: string;
99
+ loggedInPerson?: LoggedInPerson;
100
+ /** The verified seller, or null while the person may not send for the chosen one */
101
+ onSellerChange?: (selection: SellerSelection | null) => void;
102
+ /** The seller chosen before a re-login, selected and checked again */
103
+ initialSeller?: {
104
+ isSelf: boolean;
105
+ isoIdentifier: string;
106
+ };
107
+ onRepresentedCompaniesChange?: (companies: BusinessEntityCollectionResource[]) => void;
108
+ isSessionExpiring?: () => boolean;
109
+ onSessionExpired?: () => void;
94
110
  }
95
111
  declare const SupplierIntl: React.ForwardRefExoticComponent<import("react-intl").Omit<Props, "intl"> & {
96
112
  forwardedRef?: React.Ref<any>;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -42,6 +53,8 @@ var __1 = require("..");
42
53
  var react_use_1 = require("react-use");
43
54
  var CommonTranslations_1 = require("../CommonTranslations");
44
55
  var CityAutofill_1 = __importDefault(require("./CityAutofill"));
56
+ var SendOnBehalfOf_1 = __importDefault(require("./SendOnBehalfOf"));
57
+ var ConversionUtility_1 = require("../../../utils/ConversionUtility");
45
58
  exports.translationMessages = (0, react_intl_1.defineMessages)({
46
59
  supplier_title: {
47
60
  id: "supplier_title",
@@ -121,11 +134,50 @@ exports.translationMessages = (0, react_intl_1.defineMessages)({
121
134
  },
122
135
  });
123
136
  var Supplier = function (props) {
137
+ var _a, _b;
124
138
  var width = (0, react_use_1.useWindowSize)().width;
125
- var _a = (0, react_1.useState)(false), isMobile = _a[0], setIsMobile = _a[1];
126
- var _b = (0, react_1.useState)(false), isLoadingParticipantInfo = _b[0], setIsLoadingParticipantInfo = _b[1];
127
- var _c = (0, react_1.useState)({}), participantInfo = _c[0], setParticipantInfo = _c[1];
139
+ var _c = (0, react_1.useState)(false), isMobile = _c[0], setIsMobile = _c[1];
140
+ var _d = (0, react_1.useState)(false), isLoadingParticipantInfo = _d[0], setIsLoadingParticipantInfo = _d[1];
141
+ var _e = (0, react_1.useState)({}), participantInfo = _e[0], setParticipantInfo = _e[1];
128
142
  var colorInfoBg = antd_1.theme.useToken().token.colorInfoBg;
143
+ var isLoggedIn = !!props.accessToken && !!props.loggedInPerson;
144
+ // with login, kennitala and name always come from Auðkenni or the register; the address too when sending for a company
145
+ var _f = (0, react_1.useState)(false), isAddressLocked = _f[0], setIsAddressLocked = _f[1];
146
+ var _g = (0, react_1.useState)([]), activeVatNumbers = _g[0], setActiveVatNumbers = _g[1];
147
+ var _h = (0, react_1.useState)([]), vatActivities = _h[0], setVatActivities = _h[1];
148
+ var onSellerChange = function (seller, selection) {
149
+ var _a, _b, _c, _d;
150
+ var isSelf = (_a = selection === null || selection === void 0 ? void 0 : selection.isSelf) !== null && _a !== void 0 ? _a : false;
151
+ var _activeVatNumbers = ((_b = seller === null || seller === void 0 ? void 0 : seller.vatNumbers) !== null && _b !== void 0 ? _b : []).filter(function (vat) { return vat.active; });
152
+ setActiveVatNumbers(_activeVatNumbers);
153
+ setVatActivities(((_c = seller === null || seller === void 0 ? void 0 : seller.activities) !== null && _c !== void 0 ? _c : []).filter(function (activity) { return activity.type === "VAT"; }));
154
+ setIsAddressLocked(!!seller && !isSelf);
155
+ var hasAddress = !!(seller === null || seller === void 0 ? void 0 : seller.streetNameAndNumber);
156
+ props.form.setFieldsValue({
157
+ invoice: {
158
+ supplier: __assign(__assign({ identifier: (0, ConversionUtility_1.getKennitalaFromIsoIdentifier)(seller === null || seller === void 0 ? void 0 : seller.legalIdentifier, { dashed: true }), name: seller === null || seller === void 0 ? void 0 : seller.name, vatNumber: _activeVatNumbers.length === 1 ? _activeVatNumbers[0].identifier : undefined }, (hasAddress || !isSelf ? {
159
+ address: { streetNameAndNumber: seller === null || seller === void 0 ? void 0 : seller.streetNameAndNumber, postalZone: seller === null || seller === void 0 ? void 0 : seller.postalCode, city: seller === null || seller === void 0 ? void 0 : seller.city },
160
+ } : {})), (isSelf && props.loggedInPerson && !props.form.getFieldValue(["invoice", "supplier", "contact", "name"])
161
+ ? { contact: { name: props.loggedInPerson.name } } : {})),
162
+ },
163
+ });
164
+ (_d = props.onSellerChange) === null || _d === void 0 ? void 0 : _d.call(props, seller ? selection : null);
165
+ };
166
+ /** e.g. "123456 — ÍSAT 62.01.0 Hugbúnaðargerð"; the activity name comes from the register's VAT activities */
167
+ var vatNumberLabel = function (vat) {
168
+ if (!vat.classification)
169
+ return vat.identifier;
170
+ var activity = vatActivities.find(function (a) { return a.vatNumber === vat.identifier && a.code === vat.classification; });
171
+ return "".concat(vat.identifier, " \u2014 \u00CDSAT ").concat(vat.classification).concat((activity === null || activity === void 0 ? void 0 : activity.name) ? " ".concat(activity.name) : "");
172
+ };
173
+ /** VSK nr.: a dropdown of the seller's active VAT registrations (with ÍSAT activity) when the register knows them */
174
+ var renderVatNumberInput = function (disabled) { return isLoggedIn && activeVatNumbers.length > 0 ? (React.createElement(antd_1.Select, { disabled: disabled, options: activeVatNumbers.map(function (vat) {
175
+ var _a;
176
+ return ({
177
+ value: (_a = vat.identifier) !== null && _a !== void 0 ? _a : "",
178
+ label: vatNumberLabel(vat),
179
+ });
180
+ }) })) : (React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.vatNumber"], disabled: disabled, defaultIsRequired: getRequiredVatNumber(), defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_vatNumber) })); };
129
181
  (0, react_1.useEffect)(function () {
130
182
  if (width < 768) {
131
183
  setIsMobile(true);
@@ -138,8 +190,9 @@ var Supplier = function (props) {
138
190
  return !props.outsideVatScope;
139
191
  };
140
192
  (0, react_1.useEffect)(function () {
141
- if (participantInfo !== null && participantInfo !== undefined) {
142
- // TODO: this will override the Form Initial values. consider changing so that it only overrides if there is a value
193
+ // only the anonymous lookup (by typed identifier) populates legalName; skip the mount-time empty state so it
194
+ // doesn't clear the supplier name/address that the "Myself"/"On behalf of" selection just filled in
195
+ if (participantInfo === null || participantInfo === void 0 ? void 0 : participantInfo.legalName) {
143
196
  props.form.setFieldsValue({
144
197
  invoice: {
145
198
  supplier: {
@@ -157,7 +210,7 @@ var Supplier = function (props) {
157
210
  }, [isLoadingParticipantInfo]);
158
211
  var getParticipantInfoWithIdentifier = function (rapiUrl, token, searchValue) {
159
212
  setIsLoadingParticipantInfo(true);
160
- var constructedUrl = "".concat(rapiUrl, "/api/v1/participants/0196:").concat(searchValue, "/registrations");
213
+ var constructedUrl = "".concat(rapiUrl, "/api/v1/participants/").concat((0, ConversionUtility_1.getIdentifierWithPrefix)(searchValue), "/registrations");
161
214
  axios_1.default
162
215
  .get(constructedUrl, {
163
216
  cancelToken: (0, ApiUtility_1.getCancelToken)("referenceIdentifierValueSearch", false),
@@ -219,6 +272,7 @@ var Supplier = function (props) {
219
272
  padding: isMobile ? 0 : "35px",
220
273
  }, justify: "center" },
221
274
  React.createElement(antd_1.Flex, { vertical: true, style: { width: "100%", maxWidth: "900px" }, gap: isMobile ? "small" : "middle" },
275
+ isLoggedIn && (React.createElement(SendOnBehalfOf_1.default, { rapiBaseUrl: props.rapiBaseUrl, accessToken: props.accessToken, loggedInPerson: props.loggedInPerson, isMobile: props.isMobile, onSellerChange: onSellerChange, initialSeller: props.initialSeller, onRepresentedCompaniesChange: props.onRepresentedCompaniesChange, isSessionExpiring: (_a = props.isSessionExpiring) !== null && _a !== void 0 ? _a : (function () { return false; }), onSessionExpired: (_b = props.onSessionExpired) !== null && _b !== void 0 ? _b : (function () { return undefined; }) })),
222
276
  React.createElement(antd_1.Row, { gutter: 60 },
223
277
  React.createElement(antd_1.Col, { span: 24 },
224
278
  React.createElement(Title_1.default, { level: 5 }, props.intl.formatMessage(exports.translationMessages.supplier_title))),
@@ -233,11 +287,11 @@ var Supplier = function (props) {
233
287
  message: props.intl.formatMessage(form_item_2.translationMessages.formItem_required_errorMessage),
234
288
  },
235
289
  ], normalize: formatIdentifierInput, validateTrigger: ["onBlur", "onChange"] },
236
- React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.identifier"], defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_identifier), defaultIsRequired: true, disabled: isLoadingParticipantInfo, onChange: function (value) {
237
- return debouncerSearch(props.rapiBaseUrl, props.rapiApiKey, value.target.value);
290
+ React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.identifier"], defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_identifier), defaultIsRequired: true, disabled: isLoadingParticipantInfo || isLoggedIn, locked: isLoggedIn, onChange: function (value) {
291
+ return !isLoggedIn && debouncerSearch(props.rapiBaseUrl, props.rapiApiKey, value.target.value);
238
292
  } })),
239
293
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.name"], defaultLabel: props.intl.formatMessage(exports.translationMessages.supplier_name), defaultIsRequired: true, fieldName: ["invoice", "supplier", "name"] },
240
- React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.name"], disabled: isLoadingParticipantInfo, defaultIsRequired: true, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_name) })),
294
+ React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.name"], disabled: isLoadingParticipantInfo || isLoggedIn, locked: isLoggedIn, defaultIsRequired: true, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_name) })),
241
295
  props.isMobile && (React.createElement(antd_1.Row, { gutter: 20, wrap: false },
242
296
  React.createElement(antd_1.Col, { flex: "auto" },
243
297
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.vatNumber"], defaultLabel: props.intl.formatMessage(exports.translationMessages.supplier_vatNumber), defaultIsRequired: getRequiredVatNumber(), fieldName: ["invoice", "supplier", "vatNumber"], dependencies: ["invoice", "invoiceLines"], additionalRules: [
@@ -246,23 +300,21 @@ var Supplier = function (props) {
246
300
  min: 5,
247
301
  message: props.intl.formatMessage(exports.translationMessages.supplier_vatValidationMessage),
248
302
  },
249
- ] },
250
- React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.vatNumber"], disabled: isLoadingParticipantInfo ||
251
- props.form.getFieldValue(["outsideVatScope"]), defaultIsRequired: getRequiredVatNumber(), defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_vatNumber) }))),
303
+ ] }, renderVatNumberInput(isLoadingParticipantInfo || props.form.getFieldValue(["outsideVatScope"])))),
252
304
  React.createElement(antd_1.Col, { flex: "none" },
253
305
  React.createElement(antd_1.Form.Item, { name: "outsideVatScope", valuePropName: "checked" },
254
306
  React.createElement(antd_1.Checkbox, { onChange: function (e) { return props.setOutsideVatScope(e.target.checked); } }, props.intl.formatMessage(exports.translationMessages.supplier_notVatRegistered)))))),
255
307
  props.isMobile ? (React.createElement(React.Fragment, null,
256
308
  React.createElement(antd_1.Row, null,
257
- React.createElement(CityAutofill_1.default, { receiverRequirements: props.receiverRequirements, form: props.form, disabled: isLoadingParticipantInfo, defaultIsRequired: false, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_city) })),
309
+ React.createElement(CityAutofill_1.default, { receiverRequirements: props.receiverRequirements, form: props.form, disabled: isLoadingParticipantInfo || isAddressLocked, locked: isAddressLocked, defaultIsRequired: false, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_city) })),
258
310
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.streetNameAndNumber"], defaultLabel: props.intl.formatMessage(exports.translationMessages.supplier_address_streetNameAndNumber), defaultIsRequired: true, fieldName: ["invoice", "supplier", "address", "streetNameAndNumber"] },
259
- React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.streetNameAndNumber"], defaultIsRequired: true, disabled: isLoadingParticipantInfo, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_streetNameAndNumber) })),
311
+ React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.streetNameAndNumber"], defaultIsRequired: true, disabled: isLoadingParticipantInfo || isAddressLocked, locked: isAddressLocked, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_streetNameAndNumber) })),
260
312
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.countryCode"], defaultLabel: props.intl.formatMessage(exports.translationMessages.supplier_address_countryCode), defaultIsRequired: true, fieldName: ["invoice", "supplier", "address", "countryCode"] },
261
313
  React.createElement(antd_1.Input, { disabled: true })))) : (React.createElement(React.Fragment, null,
262
314
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.streetNameAndNumber"], defaultLabel: props.intl.formatMessage(exports.translationMessages.supplier_address_streetNameAndNumber), defaultIsRequired: true, fieldName: ["invoice", "supplier", "address", "streetNameAndNumber"] },
263
- React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.streetNameAndNumber"], defaultIsRequired: true, disabled: isLoadingParticipantInfo, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_streetNameAndNumber) })),
315
+ React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.streetNameAndNumber"], defaultIsRequired: true, disabled: isLoadingParticipantInfo || isAddressLocked, locked: isAddressLocked, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_streetNameAndNumber) })),
264
316
  React.createElement(antd_1.Row, { gutter: 10 },
265
- React.createElement(CityAutofill_1.default, { receiverRequirements: props.receiverRequirements, form: props.form, defaultIsRequired: false, disabled: isLoadingParticipantInfo, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_city) }),
317
+ React.createElement(CityAutofill_1.default, { receiverRequirements: props.receiverRequirements, form: props.form, defaultIsRequired: false, disabled: isLoadingParticipantInfo || isAddressLocked, locked: isAddressLocked, defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_address_city) }),
266
318
  React.createElement(antd_1.Col, { span: 6 },
267
319
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.address.countryCode"], defaultLabel: props.intl.formatMessage(exports.translationMessages.supplier_address_countryCode), defaultIsRequired: true, fieldName: ["invoice", "supplier", "address", "countryCode"] },
268
320
  React.createElement(antd_1.Input, { disabled: true }))))))),
@@ -286,8 +338,7 @@ var Supplier = function (props) {
286
338
  min: 5,
287
339
  message: props.intl.formatMessage(exports.translationMessages.supplier_vatValidationMessage),
288
340
  },
289
- ] },
290
- React.createElement(__1.UmzInput, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.vatNumber"], disabled: isLoadingParticipantInfo || props.outsideVatScope, defaultIsRequired: getRequiredVatNumber(), defaultPlaceholder: props.intl.formatMessage(exports.translationMessages.supplier_vatNumber) }))),
341
+ ] }, renderVatNumberInput(isLoadingParticipantInfo || props.outsideVatScope))),
291
342
  React.createElement(antd_1.Col, { flex: "none" },
292
343
  React.createElement(antd_1.Form.Item, { name: "outsideVatScope", valuePropName: "checked" },
293
344
  React.createElement(antd_1.Checkbox, { onChange: function (e) { return props.setOutsideVatScope(e.target.checked); }, defaultChecked: props.outsideVatScope }, props.intl.formatMessage(exports.translationMessages.supplier_notVatRegistered))))))),
@@ -30,5 +30,21 @@ export interface CommonProps {
30
30
  colorError?: string;
31
31
  colorLink?: string;
32
32
  colorInfoBg?: string;
33
+ /** IdentityServer access token when the portal requires login; the supplier then sends for themselves or a company they represent */
34
+ accessToken?: string;
35
+ loggedInPerson?: LoggedInPerson;
36
+ /** When the access token expires (ms since epoch); the wizard saves its state and asks the host to log in again before that */
37
+ accessTokenExpiresAt?: number;
38
+ /** Called when the person must log in again; the host redirects to IdentityServer and the wizard restores its state on return */
39
+ onLoginRequired?: () => void;
40
+ /** IdentityServer page where a procuration holder grants or revokes delegations (umboð) */
41
+ delegationsUrl?: string;
42
+ /** Shows "Log out" in the session bar; called when the person wants to end their session */
43
+ onLogout?: () => void;
44
+ }
45
+ export interface LoggedInPerson {
46
+ /** e.g. 0196:0101019990 */
47
+ isoIdentifier: string;
48
+ name: string;
33
49
  }
34
50
  export type LanguageProp = "en" | "is" | undefined;
@@ -0,0 +1,16 @@
1
+ /** Register role that allows sending for a company and granting delegations */
2
+ export declare const PROCURATION = "PROCURATION";
3
+ /** An active delegation (umboð) to send invoices for a company */
4
+ export declare const GRANTED = "GRANTED";
5
+ /** Who the logged-in person sends the invoice for, chosen in the "On behalf of" banner */
6
+ export interface SellerSelection {
7
+ /** True when the person sends for themselves */
8
+ isSelf: boolean;
9
+ /** e.g. 0196:4401019990 */
10
+ isoIdentifier: string;
11
+ name: string;
12
+ /** The person's roles for the seller (PROCURATION, GRANTED, …); empty for themselves */
13
+ roles: string[];
14
+ }
15
+ /** May send for a company: procuration holder or an active delegation */
16
+ export declare const mayRepresent: (roles?: string[] | null) => boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mayRepresent = exports.GRANTED = exports.PROCURATION = void 0;
4
+ /** Register role that allows sending for a company and granting delegations */
5
+ exports.PROCURATION = "PROCURATION";
6
+ /** An active delegation (umboð) to send invoices for a company */
7
+ exports.GRANTED = "GRANTED";
8
+ /** May send for a company: procuration holder or an active delegation */
9
+ var mayRepresent = function (roles) { return (roles !== null && roles !== void 0 ? roles : []).some(function (role) { return role === exports.PROCURATION || role === exports.GRANTED; }); };
10
+ exports.mayRepresent = mayRepresent;
@@ -111,6 +111,6 @@ var CreateInvoice = function (props) {
111
111
  react_1.default.createElement(react_intl_1.IntlProvider, { locale: languageString, defaultLocale: "is", key: languageString, messages: locales_1.default[languageString] },
112
112
  react_1.default.createElement(index_1.default, { customers: props.customers, language: languageString, mapiBaseUrl: props.mapiBaseUrl, rapiBaseUrl: props.rapiBaseUrl, localStorageFormDataVersion: props.localStorageFormDataVersion, rapiApiKey: props.rapiApiKey, receiverRequirements: props.receiverRequirements, getReceiverRequirements: props.getReceiverRequirements, updateReceiverRequirementsProp: props.updateReceiverRequirementsProp,
113
113
  // legalIdentifier={props.legalIdentifier}
114
- uploadSizeLimit: props.uploadSizeLimit, attachmentTooltipText: props.attachmentTooltipText, referenceIdentifiersHelpText: props.referenceIdentifiersHelpText, referenceIdentifiersLabelText: props.referenceIdentifiersLabelText, dueDateMinimumOffset: props.dueDateMinimumOffset, defaultPaymentType: props.defaultPaymentType, supportEmail: props.supportEmail, welcomeModalTitle: props.welcomeModalTitle, welcomeModalParagraph: props.welcomeModalParagraph, welcomeModalImageUrl: props.welcomeModalImageUrl, colorPrimary: props.colorPrimary, colorError: props.colorError }))));
114
+ uploadSizeLimit: props.uploadSizeLimit, attachmentTooltipText: props.attachmentTooltipText, referenceIdentifiersHelpText: props.referenceIdentifiersHelpText, referenceIdentifiersLabelText: props.referenceIdentifiersLabelText, dueDateMinimumOffset: props.dueDateMinimumOffset, defaultPaymentType: props.defaultPaymentType, supportEmail: props.supportEmail, welcomeModalTitle: props.welcomeModalTitle, welcomeModalParagraph: props.welcomeModalParagraph, welcomeModalImageUrl: props.welcomeModalImageUrl, colorPrimary: props.colorPrimary, colorError: props.colorError, accessToken: props.accessToken, loggedInPerson: props.loggedInPerson, accessTokenExpiresAt: props.accessTokenExpiresAt, onLoginRequired: props.onLoginRequired, delegationsUrl: props.delegationsUrl, onLogout: props.onLogout }))));
115
115
  };
116
116
  exports.default = CreateInvoice;
@@ -74,6 +74,14 @@ export declare const translationMessages: {
74
74
  id: string;
75
75
  defaultMessage: string;
76
76
  };
77
+ createInvoice_sessionExpired: {
78
+ id: string;
79
+ defaultMessage: string;
80
+ };
81
+ createInvoice_attachmentsNotRestored: {
82
+ id: string;
83
+ defaultMessage: string;
84
+ };
77
85
  };
78
86
  export interface AttachmentProps {
79
87
  description: string;