@unimaze/billing 0.21.71 → 1.0.0

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 +34 -0
  9. package/lib/common/components/session-bar/index.js +79 -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 +66 -16
  16. package/lib/common/types/CommonProps.d.ts +14 -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 +23 -0
  24. package/lib/translations/locales/is.json +23 -0
  25. package/lib/translations/locales.d.ts +46 -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
@@ -3,7 +3,11 @@ import { Store } from "antd/es/form/interface";
3
3
  import { PortalConfigurationCustomer } from "@unimaze/api-clients/lib/rapi";
4
4
  import { PaymentMeansMetadata } from "@unimaze/api-clients/lib/mapi/api";
5
5
  export declare const removeEmpty: (obj: any) => any;
6
+ declare const stripToDigits: (value?: string | null) => string;
7
+ declare const getIdentifierWithPrefix: (identifier?: string | null) => string;
8
+ declare const getKennitalaFromIsoIdentifier: (isoIdentifier?: string | null, options?: {
9
+ dashed?: boolean;
10
+ }) => string;
6
11
  declare const convertToInvoiceMetadataInput: (formValues: Store, invoiceLinesWithCalculations: BillingLineMetadata[], paymentMethod: PaymentMeansMetadata, chosenCustomer: PartyMetadata) => InvoiceMetadataInput;
7
12
  declare const profileOutputToPartyMetadata: (customer: PortalConfigurationCustomer) => PartyMetadata;
8
- declare const convertToReadableKennitala: (isoIdentifier: string) => string;
9
- export { convertToInvoiceMetadataInput, profileOutputToPartyMetadata, convertToReadableKennitala };
13
+ export { convertToInvoiceMetadataInput, profileOutputToPartyMetadata, getIdentifierWithPrefix, getKennitalaFromIsoIdentifier, stripToDigits };
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.convertToReadableKennitala = exports.profileOutputToPartyMetadata = exports.convertToInvoiceMetadataInput = exports.removeEmpty = void 0;
17
+ exports.stripToDigits = exports.getKennitalaFromIsoIdentifier = exports.getIdentifierWithPrefix = exports.profileOutputToPartyMetadata = exports.convertToInvoiceMetadataInput = exports.removeEmpty = void 0;
18
18
  var dayjs_1 = __importDefault(require("dayjs"));
19
19
  var antd_1 = require("antd");
20
20
  var utc_1 = __importDefault(require("dayjs/plugin/utc"));
@@ -50,18 +50,24 @@ var isEmpty = function (map) {
50
50
  }
51
51
  return true;
52
52
  };
53
+ var KENNITALA_ISO_PREFIX = "0196:";
54
+ var stripToDigits = function (value) {
55
+ return (value !== null && value !== void 0 ? value : "").replace(/\D/g, "");
56
+ };
57
+ exports.stripToDigits = stripToDigits;
58
+ // kennitala (dashed, plain, or already-ISO) -> "0196:XXXXXXXXXX"
53
59
  var getIdentifierWithPrefix = function (identifier) {
54
- if (!identifier.startsWith("0196:")) {
55
- return "0196:".concat(cleanIdentifier(identifier));
56
- }
57
- else {
58
- return cleanIdentifier(identifier);
59
- }
60
+ return "".concat(KENNITALA_ISO_PREFIX).concat(stripToDigits((identifier !== null && identifier !== void 0 ? identifier : "").replace(KENNITALA_ISO_PREFIX, "")));
60
61
  };
61
- var cleanIdentifier = function (identifier) {
62
- // return identifier.replace(/[^0-9]/g, "") // replace anything that isn't a numeric character
63
- return identifier.replace("-", ""); // remove the '-'
62
+ exports.getIdentifierWithPrefix = getIdentifierWithPrefix;
63
+ // "0196:XXXXXXXXXX" -> "XXXXXX-XXXX" (or raw digits if not exactly 10, or `dashed: false`)
64
+ var getKennitalaFromIsoIdentifier = function (isoIdentifier, options) {
65
+ var _a;
66
+ var digits = stripToDigits((isoIdentifier !== null && isoIdentifier !== void 0 ? isoIdentifier : "").replace(KENNITALA_ISO_PREFIX, ""));
67
+ var dashed = (_a = options === null || options === void 0 ? void 0 : options.dashed) !== null && _a !== void 0 ? _a : true;
68
+ return dashed && digits.length === 10 ? "".concat(digits.slice(0, 6), "-").concat(digits.slice(6)) : digits;
64
69
  };
70
+ exports.getKennitalaFromIsoIdentifier = getKennitalaFromIsoIdentifier;
65
71
  var convertToInvoiceMetadataInput = function (formValues, invoiceLinesWithCalculations, paymentMethod, chosenCustomer) {
66
72
  var _a, _b, _c;
67
73
  var issueDate = convertDates(formValues.invoice.issueDate);
@@ -218,7 +224,3 @@ var profileOutputToPartyMetadata = function (customer) {
218
224
  };
219
225
  };
220
226
  exports.profileOutputToPartyMetadata = profileOutputToPartyMetadata;
221
- var convertToReadableKennitala = function (isoIdentifier) {
222
- return "".concat(isoIdentifier.substr(5, 6), "-").concat(isoIdentifier.substr(11));
223
- };
224
- exports.convertToReadableKennitala = convertToReadableKennitala;
@@ -0,0 +1,20 @@
1
+ export interface WizardSnapshot {
2
+ /** form.getFieldsValue(true) without attachments */
3
+ values: any;
4
+ activeStep: number;
5
+ chosenCustomer: any;
6
+ removedInvoiceLine: any;
7
+ /** The seller chosen in the "On behalf of" banner, re-checked after the login */
8
+ seller?: {
9
+ isSelf: boolean;
10
+ isoIdentifier: string;
11
+ };
12
+ /** True when the form had attachments that could not be kept */
13
+ hadAttachments: boolean;
14
+ }
15
+ /** Builds a snapshot from the form values; attachments are dropped */
16
+ export declare const createWizardSnapshot: (values: any, rest: Omit<WizardSnapshot, "values" | "hadAttachments">) => WizardSnapshot;
17
+ export declare const saveWizardSnapshot: (snapshot: WizardSnapshot) => void;
18
+ /** The saved snapshot, if any; call clearWizardSnapshot once it is restored */
19
+ export declare const readWizardSnapshot: () => WizardSnapshot | undefined;
20
+ export declare const clearWizardSnapshot: () => void;
@@ -0,0 +1,88 @@
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 __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.clearWizardSnapshot = exports.readWizardSnapshot = exports.saveWizardSnapshot = exports.createWizardSnapshot = void 0;
29
+ var dayjs_1 = __importDefault(require("dayjs"));
30
+ /**
31
+ * Keeps the invoice wizard's state across a re-login: when the IdentityServer access token expires, the wizard is saved
32
+ * to sessionStorage, the host redirects to the login and the wizard is restored when it mounts again.
33
+ * Attachments are files and cannot be stored; the person adds them again.
34
+ */
35
+ var SNAPSHOT_KEY = "billing.wizardSnapshot";
36
+ var DAYJS_MARKER = "__dayjs";
37
+ var EMPTY_ATTACHMENTS = {
38
+ file1: { file: undefined, description: undefined },
39
+ file2: { file: undefined, description: undefined },
40
+ file3: { file: undefined, description: undefined },
41
+ };
42
+ var hasAttachments = function (attachments) {
43
+ return !!attachments && Object.values(attachments).some(function (attachment) { return !!(attachment === null || attachment === void 0 ? void 0 : attachment.file); });
44
+ };
45
+ /** Builds a snapshot from the form values; attachments are dropped */
46
+ var createWizardSnapshot = function (values, rest) {
47
+ var _a = values !== null && values !== void 0 ? values : {}, attachments = _a.attachments, valuesWithoutAttachments = __rest(_a, ["attachments"]);
48
+ return __assign(__assign({}, rest), { values: __assign(__assign({}, valuesWithoutAttachments), { attachments: EMPTY_ATTACHMENTS }), hadAttachments: hasAttachments(attachments) });
49
+ };
50
+ exports.createWizardSnapshot = createWizardSnapshot;
51
+ var saveWizardSnapshot = function (snapshot) {
52
+ try {
53
+ // dayjs values (issue and due date) serialise to strings; mark them so they come back as dayjs
54
+ var json = JSON.stringify(snapshot, function (key, value) {
55
+ var _a;
56
+ return dayjs_1.default.isDayjs(this[key]) ? (_a = {}, _a[DAYJS_MARKER] = this[key].toISOString(), _a) : value;
57
+ });
58
+ sessionStorage.setItem(SNAPSHOT_KEY, json);
59
+ }
60
+ catch (_a) {
61
+ // storage unavailable or full: the person fills in the form again
62
+ }
63
+ };
64
+ exports.saveWizardSnapshot = saveWizardSnapshot;
65
+ /** The saved snapshot, if any; call clearWizardSnapshot once it is restored */
66
+ var readWizardSnapshot = function () {
67
+ try {
68
+ var json = sessionStorage.getItem(SNAPSHOT_KEY);
69
+ if (!json)
70
+ return undefined;
71
+ return JSON.parse(json, function (_key, value) {
72
+ return value && typeof value === "object" && typeof value[DAYJS_MARKER] === "string" ? (0, dayjs_1.default)(value[DAYJS_MARKER]) : value;
73
+ });
74
+ }
75
+ catch (_a) {
76
+ return undefined;
77
+ }
78
+ };
79
+ exports.readWizardSnapshot = readWizardSnapshot;
80
+ var clearWizardSnapshot = function () {
81
+ try {
82
+ sessionStorage.removeItem(SNAPSHOT_KEY);
83
+ }
84
+ catch (_a) {
85
+ // nothing to clear
86
+ }
87
+ };
88
+ exports.clearWizardSnapshot = clearWizardSnapshot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unimaze/billing",
3
- "version": "0.21.71",
3
+ "version": "1.0.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "@ant-design/compatible": "latest",
12
- "@unimaze/api-clients": "3.2.0",
12
+ "@unimaze/api-clients": "4.0.0",
13
13
  "antd-mask-input": "^0.1.13",
14
14
  "chardet": "^2.2.0",
15
15
  "dayjs": "^1.11.10",
@@ -1,10 +0,0 @@
1
- import * as React from "react";
2
- import { AttachmentType } from "./index";
3
- import { UploadFile } from "antd/es/upload/interface";
4
- interface Props {
5
- attachments: AttachmentType[];
6
- setIsModalOpen: (isModalOpen: boolean) => void;
7
- removeFile: (file: UploadFile) => void;
8
- }
9
- declare const ListAttachments: React.FC<Props>;
10
- export default ListAttachments;
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- var React = __importStar(require("react"));
63
- var antd_1 = require("antd");
64
- var icons_1 = require("@ant-design/icons");
65
- var index_1 = require("./index");
66
- var react_intl_1 = require("react-intl");
67
- var FileUploadUtility_1 = require("../../../utils/FileUploadUtility");
68
- var ListAttachments = function (_a) {
69
- var attachments = _a.attachments, setIsModalOpen = _a.setIsModalOpen, removeFile = _a.removeFile;
70
- var _b = React.useState(false), previewOpen = _b[0], setPreviewOpen = _b[1];
71
- var _c = React.useState(undefined), previewImage = _c[0], setPreviewImage = _c[1];
72
- var _d = React.useState(""), previewDescription = _d[0], setPreviewDescription = _d[1];
73
- var _e = React.useState(""), previewPDFUrl = _e[0], setPreviewPDFUrl = _e[1];
74
- var intl = (0, react_intl_1.useIntl)();
75
- var token = antd_1.theme.useToken().token;
76
- var handlePreview = function (file, description) { return __awaiter(void 0, void 0, void 0, function () {
77
- var reader, _a;
78
- return __generator(this, function (_b) {
79
- switch (_b.label) {
80
- case 0:
81
- if (!file.originFileObj)
82
- return [2 /*return*/];
83
- if (!(file.type === "application/pdf")) return [3 /*break*/, 1];
84
- reader = new FileReader();
85
- reader.onload = function (e) {
86
- var blob = file.originFileObj ? new Blob([file.originFileObj], { type: "application/pdf" }) : null;
87
- if (blob) {
88
- var url = URL.createObjectURL(blob);
89
- setPreviewPDFUrl(url);
90
- }
91
- };
92
- reader.readAsArrayBuffer(file.originFileObj);
93
- return [3 /*break*/, 4];
94
- case 1:
95
- if (!(!file.url && !file.preview)) return [3 /*break*/, 3];
96
- _a = file;
97
- return [4 /*yield*/, (0, FileUploadUtility_1.getBase64)(file.originFileObj)];
98
- case 2:
99
- _a.preview = (_b.sent());
100
- _b.label = 3;
101
- case 3:
102
- setPreviewImage(file.url || file.preview);
103
- _b.label = 4;
104
- case 4:
105
- setPreviewDescription(description);
106
- setPreviewOpen(true);
107
- return [2 /*return*/];
108
- }
109
- });
110
- }); };
111
- var handleClosePreview = function () {
112
- if (previewPDFUrl) {
113
- URL.revokeObjectURL(previewPDFUrl);
114
- setPreviewPDFUrl("");
115
- }
116
- if (previewImage) {
117
- setPreviewImage("");
118
- }
119
- setPreviewDescription("");
120
- setPreviewOpen(false);
121
- };
122
- return (React.createElement(React.Fragment, null,
123
- React.createElement(antd_1.Flex, { vertical: true, gap: "small" },
124
- React.createElement(antd_1.Flex, { vertical: true },
125
- React.createElement(antd_1.Typography.Text, { disabled: true }, intl.formatMessage(index_1.translationMessages.attachment_title))),
126
- React.createElement(antd_1.Divider, { style: { padding: 0, margin: 0 } }),
127
- attachments.map(function (attachment) { return (React.createElement(antd_1.Flex, { key: attachment.uid, gap: "middle", justify: "space-between" },
128
- React.createElement(antd_1.Button, { type: "link", onClick: function () { return handlePreview(attachment.file, attachment.description); }, style: { padding: 0 }, size: "small" },
129
- React.createElement(icons_1.PaperClipOutlined, { style: { fontSize: token.fontSizeIcon } }),
130
- attachment.file.name),
131
- React.createElement(antd_1.Flex, { gap: "middle" },
132
- React.createElement(icons_1.EditOutlined, { style: { fontSize: token.fontSizeHeading4 }, onClick: function () {
133
- setIsModalOpen(true);
134
- } }),
135
- React.createElement(icons_1.DeleteOutlined, { style: { fontSize: token.fontSizeHeading4 }, onClick: function () {
136
- removeFile(attachment.file);
137
- } })))); })),
138
- React.createElement(antd_1.Modal, { open: previewOpen, onCancel: handleClosePreview, footer: null },
139
- previewPDFUrl && (React.createElement("iframe", { src: previewPDFUrl, style: { width: "100%", height: "700px", maxHeight: "75vh" } })),
140
- previewImage && React.createElement(antd_1.Image, { src: previewImage, preview: false }),
141
- React.createElement(antd_1.Typography.Text, null, previewDescription))));
142
- };
143
- exports.default = ListAttachments;