@unimaze/billing 0.12.13 → 0.12.15
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/common/components/attachments/Attachment.d.ts +5 -11
- package/lib/common/components/attachments/Attachment.js +77 -96
- package/lib/common/components/attachments/index.d.ts +15 -1
- package/lib/common/components/attachments/index.js +3 -3
- package/lib/common/components/base-information/AccountingCost.d.ts +15 -0
- package/lib/common/components/base-information/AccountingCost.js +40 -0
- package/lib/common/components/base-information/index.js +2 -0
- package/lib/common/components/billing-lines/NewBillingLines.js +5 -1
- package/lib/common/components/form-item/index.d.ts +1 -1
- package/lib/create-invoice/index.js +57 -73
- package/lib/translations/locales/is.json +3 -0
- package/lib/translations/locales.d.ts +3 -0
- package/lib/utils/BillingLineUtility.d.ts +1 -1
- package/lib/utils/ConversionUtility.js +1 -1
- package/lib/utils/RequirementsUtility.d.ts +8 -0
- package/lib/utils/RequirementsUtility.js +90 -0
- package/package.json +1 -1
|
@@ -7,18 +7,12 @@ interface Props extends InjectedIntlProps {
|
|
|
7
7
|
fieldName: "file1" | "file2" | "file3";
|
|
8
8
|
formInstance: FormInstance;
|
|
9
9
|
uploadSizeLimit: number;
|
|
10
|
-
}
|
|
11
|
-
interface States {
|
|
12
10
|
file: UploadFile[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor(props: Props);
|
|
17
|
-
handleRemoveFile: () => void;
|
|
18
|
-
normFile: (e: any) => any;
|
|
19
|
-
render(): JSX.Element;
|
|
11
|
+
setFile: (file: UploadFile[]) => void;
|
|
12
|
+
attachmentFieldValidation: ValidateStatus;
|
|
13
|
+
setAttachmentFieldValidation: (attachmentFieldValidation: ValidateStatus) => void;
|
|
20
14
|
}
|
|
21
|
-
declare const _default: React.ComponentClass<Pick<Props
|
|
22
|
-
WrappedComponent: React.ComponentType<Props &
|
|
15
|
+
declare const _default: React.ComponentClass<Pick<Props, "file" | "fieldName" | "formInstance" | "uploadSizeLimit" | "setFile" | "attachmentFieldValidation" | "setAttachmentFieldValidation">, any> & {
|
|
16
|
+
WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
|
|
23
17
|
};
|
|
24
18
|
export default _default;
|
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
var __assign = (this && this.__assign) || function () {
|
|
16
3
|
__assign = Object.assign || function(t) {
|
|
17
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -79,89 +66,83 @@ var translationMessages = react_intl_1.defineMessages({
|
|
|
79
66
|
defaultMessage: "File failed to upload",
|
|
80
67
|
},
|
|
81
68
|
});
|
|
82
|
-
var Attachment =
|
|
83
|
-
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return ({
|
|
143
|
-
validator: function (rule, value) {
|
|
144
|
-
if (!value || getFieldValue(["attachments", returnOtherFieldNames(fieldName)[0], "description"]) !== value) {
|
|
145
|
-
return Promise.resolve();
|
|
146
|
-
}
|
|
147
|
-
return Promise.reject(attachmentLabelsDescriptionErrorMsg);
|
|
69
|
+
var Attachment = function (props) {
|
|
70
|
+
var fieldName = props.fieldName;
|
|
71
|
+
var handleRemoveFile = function () {
|
|
72
|
+
props.setFile([]);
|
|
73
|
+
props.setAttachmentFieldValidation("");
|
|
74
|
+
};
|
|
75
|
+
var normFile = function (e) {
|
|
76
|
+
if (Array.isArray(e)) {
|
|
77
|
+
return e;
|
|
78
|
+
}
|
|
79
|
+
props.setFile(e && e.fileList);
|
|
80
|
+
return e && e.fileList;
|
|
81
|
+
};
|
|
82
|
+
var returnOtherFieldNames = function (fn) {
|
|
83
|
+
switch (fn) {
|
|
84
|
+
case "file1":
|
|
85
|
+
return ["file2", "file3"];
|
|
86
|
+
case "file2":
|
|
87
|
+
return ["file1", "file3"];
|
|
88
|
+
case "file3":
|
|
89
|
+
return ["file1", "file2"];
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var attachmentLabelsDescriptionErrorMsg = props.intl.formatMessage(translationMessages.attachment_labels_descriptionErrorMsg);
|
|
93
|
+
var verifyTheAttachment = function (info, uploadSizeLimit, formInstance) {
|
|
94
|
+
if (info.file.status === "removed")
|
|
95
|
+
return;
|
|
96
|
+
props.setAttachmentFieldValidation("validating");
|
|
97
|
+
var ifFileIsValid = FileUploadUtility_1.reportIfFileIsValid(info.file, uploadSizeLimit, {
|
|
98
|
+
uploadErrorToLarge: props.intl.formatMessage(translationMessages.attachment_error_fileTooLarge, { uploadSizeLimit: uploadSizeLimit / 1024 }),
|
|
99
|
+
uploadErrorWrongType: props.intl.formatMessage(translationMessages.attachment_error_fileWrongType),
|
|
100
|
+
uploadFailed: props.intl.formatMessage(translationMessages.attachment_error_fileFailedToUpload),
|
|
101
|
+
});
|
|
102
|
+
if (!ifFileIsValid) {
|
|
103
|
+
formInstance.resetFields(["attachments", "" + props.fieldName, "file"]);
|
|
104
|
+
props.setAttachmentFieldValidation("error");
|
|
105
|
+
props.setFile([]);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
props.setAttachmentFieldValidation("success");
|
|
109
|
+
props.setFile([info.file]);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return (React.createElement(React.Fragment, null,
|
|
113
|
+
React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemVerticalLayout, { label: props.intl.formatMessage(translationMessages.attachment_labels_File), name: ["attachments", "" + fieldName, "file"], valuePropName: "fileList", getValueFromEvent: normFile, validateStatus: props.attachmentFieldValidation }),
|
|
114
|
+
React.createElement(antd_1.Upload.Dragger, { name: "attachment:" + fieldName, multiple: false, onRemove: handleRemoveFile, onChange: function (info) {
|
|
115
|
+
verifyTheAttachment(info, props.uploadSizeLimit, props.formInstance);
|
|
116
|
+
}, beforeUpload: function (file) { return false; }, fileList: props.file },
|
|
117
|
+
React.createElement("p", null, props.intl.formatMessage(translationMessages.attachment_labels_uploadFileMsg)))),
|
|
118
|
+
React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemVerticalLayout, { label: props.intl.formatMessage(translationMessages.attachment_labels_Description), name: ["attachments", "" + fieldName, "description"], rules: [
|
|
119
|
+
{
|
|
120
|
+
required: props.file.length > 0,
|
|
121
|
+
message: props.intl.formatMessage(translationMessages.attachment_labels_Description_requiredMessage),
|
|
122
|
+
},
|
|
123
|
+
function (_a) {
|
|
124
|
+
var getFieldValue = _a.getFieldValue;
|
|
125
|
+
return ({
|
|
126
|
+
validator: function (rule, value) {
|
|
127
|
+
if (!value || getFieldValue(["attachments", returnOtherFieldNames(fieldName)[0], "description"]) !== value) {
|
|
128
|
+
return Promise.resolve();
|
|
148
129
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return Promise.
|
|
130
|
+
return Promise.reject(attachmentLabelsDescriptionErrorMsg);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
function (_a) {
|
|
135
|
+
var getFieldValue = _a.getFieldValue;
|
|
136
|
+
return ({
|
|
137
|
+
validator: function (rule, value) {
|
|
138
|
+
if (!value || getFieldValue(["attachments", returnOtherFieldNames(fieldName)[1], "description"]) !== value) {
|
|
139
|
+
return Promise.resolve();
|
|
159
140
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
141
|
+
return Promise.reject(attachmentLabelsDescriptionErrorMsg);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
] }),
|
|
146
|
+
React.createElement(antd_1.Input, null))));
|
|
147
|
+
};
|
|
167
148
|
exports.default = react_intl_1.injectIntl(React.memo(Attachment));
|
|
@@ -2,6 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import { InjectedIntlProps } from "react-intl";
|
|
3
3
|
import { FormInstance } from "antd/es/form";
|
|
4
4
|
import { LanguageProp } from "../../types/CommonProps";
|
|
5
|
+
import { UploadFile } from "antd/es/upload/interface";
|
|
6
|
+
import { ValidateStatus } from "antd/lib/form/FormItem";
|
|
5
7
|
interface Props extends InjectedIntlProps {
|
|
6
8
|
formInstance: FormInstance;
|
|
7
9
|
uploadSizeLimit: number;
|
|
@@ -10,8 +12,20 @@ interface Props extends InjectedIntlProps {
|
|
|
10
12
|
en: string;
|
|
11
13
|
};
|
|
12
14
|
languageString: LanguageProp;
|
|
15
|
+
file1: UploadFile[];
|
|
16
|
+
setFile1: (file: UploadFile[]) => void;
|
|
17
|
+
attachmentFieldValidation1: ValidateStatus;
|
|
18
|
+
setAttachmentFieldValidation1: (attachmentFieldValidation: ValidateStatus) => void;
|
|
19
|
+
file2: UploadFile[];
|
|
20
|
+
setFile2: (file: UploadFile[]) => void;
|
|
21
|
+
attachmentFieldValidation2: ValidateStatus;
|
|
22
|
+
setAttachmentFieldValidation2: (attachmentFieldValidation: ValidateStatus) => void;
|
|
23
|
+
file3: UploadFile[];
|
|
24
|
+
setFile3: (file: UploadFile[]) => void;
|
|
25
|
+
attachmentFieldValidation3: ValidateStatus;
|
|
26
|
+
setAttachmentFieldValidation3: (attachmentFieldValidation: ValidateStatus) => void;
|
|
13
27
|
}
|
|
14
|
-
declare const AttachmentGroupIntl: React.ComponentClass<Pick<Props, "formInstance" | "uploadSizeLimit" | "attachmentTooltipText" | "languageString">, any> & {
|
|
28
|
+
declare const AttachmentGroupIntl: React.ComponentClass<Pick<Props, "file1" | "file2" | "file3" | "formInstance" | "uploadSizeLimit" | "attachmentTooltipText" | "languageString" | "setFile1" | "attachmentFieldValidation1" | "setAttachmentFieldValidation1" | "setFile2" | "attachmentFieldValidation2" | "setAttachmentFieldValidation2" | "setFile3" | "attachmentFieldValidation3" | "setAttachmentFieldValidation3">, any> & {
|
|
15
29
|
WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
|
|
16
30
|
};
|
|
17
31
|
export default AttachmentGroupIntl;
|
|
@@ -38,11 +38,11 @@ var AttachmentsGroup = function (props) {
|
|
|
38
38
|
return (React.createElement(components_1.ComponentContainer, { title: attachmentLabelNode },
|
|
39
39
|
React.createElement(antd_1.Row, { gutter: [16, 16] },
|
|
40
40
|
React.createElement(antd_1.Col, { span: 8 },
|
|
41
|
-
React.createElement(Attachment_1.default, { key: "attachment1", fieldName: "file1", formInstance: props.formInstance, uploadSizeLimit: props.uploadSizeLimit })),
|
|
41
|
+
React.createElement(Attachment_1.default, { key: "attachment1", fieldName: "file1", formInstance: props.formInstance, uploadSizeLimit: props.uploadSizeLimit, file: props.file1, setFile: props.setFile1, attachmentFieldValidation: props.attachmentFieldValidation1, setAttachmentFieldValidation: props.setAttachmentFieldValidation1 })),
|
|
42
42
|
React.createElement(antd_1.Col, { span: 8 },
|
|
43
|
-
React.createElement(Attachment_1.default, { key: "attachment2", fieldName: "file2", formInstance: props.formInstance, uploadSizeLimit: props.uploadSizeLimit })),
|
|
43
|
+
React.createElement(Attachment_1.default, { key: "attachment2", fieldName: "file2", formInstance: props.formInstance, uploadSizeLimit: props.uploadSizeLimit, file: props.file2, setFile: props.setFile2, attachmentFieldValidation: props.attachmentFieldValidation2, setAttachmentFieldValidation: props.setAttachmentFieldValidation2 })),
|
|
44
44
|
React.createElement(antd_1.Col, { span: 8 },
|
|
45
|
-
React.createElement(Attachment_1.default, { key: "attachment3", fieldName: "file3", formInstance: props.formInstance, uploadSizeLimit: props.uploadSizeLimit })))));
|
|
45
|
+
React.createElement(Attachment_1.default, { key: "attachment3", fieldName: "file3", formInstance: props.formInstance, uploadSizeLimit: props.uploadSizeLimit, file: props.file3, setFile: props.setFile3, attachmentFieldValidation: props.attachmentFieldValidation3, setAttachmentFieldValidation: props.setAttachmentFieldValidation3 })))));
|
|
46
46
|
};
|
|
47
47
|
var AttachmentGroupIntl = react_intl_1.injectIntl(AttachmentsGroup);
|
|
48
48
|
exports.default = AttachmentGroupIntl;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NewReceiverRequirements } from "../../types/NewReceiverRequirements";
|
|
3
|
+
import { FormInstance } from "antd/es/form";
|
|
4
|
+
import { InjectedIntlProps } from "react-intl";
|
|
5
|
+
interface Props extends InjectedIntlProps {
|
|
6
|
+
receiverRequirements: NewReceiverRequirements;
|
|
7
|
+
updateReceiverRequirementsProp: (receiverRequirements: NewReceiverRequirements) => void;
|
|
8
|
+
formInstance: FormInstance;
|
|
9
|
+
rapiBaseUrl: string;
|
|
10
|
+
legalIdentifier: string;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: React.ComponentClass<Pick<Props, "formInstance" | "receiverRequirements" | "updateReceiverRequirementsProp" | "rapiBaseUrl" | "legalIdentifier">, any> & {
|
|
13
|
+
WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
|
+
if (mod && mod.__esModule) return mod;
|
|
4
|
+
var result = {};
|
|
5
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
6
|
+
result["default"] = mod;
|
|
7
|
+
return result;
|
|
8
|
+
};
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
var react_1 = __importStar(require("react"));
|
|
14
|
+
var RequirementsUtility_1 = require("../../../utils/RequirementsUtility");
|
|
15
|
+
var ReceiverRequirements_1 = require("../../types/ReceiverRequirements");
|
|
16
|
+
var form_item_1 = __importDefault(require("../form-item"));
|
|
17
|
+
var react_intl_1 = require("react-intl");
|
|
18
|
+
var translationMessages = react_intl_1.defineMessages({
|
|
19
|
+
baseInformation_accountingCostLabel: {
|
|
20
|
+
id: "baseInformation_accountingCostLabel",
|
|
21
|
+
defaultMessage: "Accounting cost"
|
|
22
|
+
},
|
|
23
|
+
baseInformation_accountingCostLabel_helpText: {
|
|
24
|
+
id: "baseInformation_accountingCostLabel_helpText",
|
|
25
|
+
defaultMessage: "Accounting cost is a code provided by the buyer, either via phone or e-mail or taken directly from the an order associated with the invoice"
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
var AccountingCost = function (props) {
|
|
29
|
+
var _a = react_1.useState(""), accountingCostHandlingValidationStatus = _a[0], setAccountingCostHandlingValidationStatus = _a[1];
|
|
30
|
+
var _b = react_1.useState({}), accountingCostFieldProps = _b[0], setAccountingCostFieldProps = _b[1];
|
|
31
|
+
var _c = react_1.useState(false), loadingAccountingCostValues = _c[0], setLoadingAccountingCostValues = _c[1];
|
|
32
|
+
var accountingCostFieldDefinition = RequirementsUtility_1.getFieldRequirements(props.receiverRequirements, ReceiverRequirements_1.AvailableFields.accountingCost);
|
|
33
|
+
if (accountingCostFieldDefinition) {
|
|
34
|
+
return (react_1.default.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.accountingCost, defaultLabel: props.intl.formatMessage(translationMessages.baseInformation_accountingCostLabel), defaultLabelTooltip: props.intl.formatMessage(translationMessages.baseInformation_accountingCostLabel_helpText), defaultIsRequired: false, fieldName: ["invoice", "accountingCost"], validateStatus: accountingCostHandlingValidationStatus, hasFeedback: true }, RequirementsUtility_1.getInput(accountingCostFieldDefinition, ["invoice", "accountingCost"], "handleAccountingCostValidation", props.legalIdentifier, props.formInstance, props.rapiBaseUrl, props.receiverRequirements, props.updateReceiverRequirementsProp, setAccountingCostFieldProps, accountingCostFieldProps, setLoadingAccountingCostValues, loadingAccountingCostValues, setAccountingCostHandlingValidationStatus)));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.default = react_intl_1.injectIntl(AccountingCost);
|
|
@@ -20,6 +20,7 @@ var ReferenceIdentifiers_1 = __importStar(require("./ReferenceIdentifiers"));
|
|
|
20
20
|
var icons_1 = require("@ant-design/icons");
|
|
21
21
|
var RequirementsUtility_1 = require("../../../utils/RequirementsUtility");
|
|
22
22
|
var OrderReference_1 = __importDefault(require("./OrderReference"));
|
|
23
|
+
var AccountingCost_1 = __importDefault(require("./AccountingCost"));
|
|
23
24
|
var translationMessages = react_intl_1.defineMessages({
|
|
24
25
|
baseInformation_title: {
|
|
25
26
|
id: "baseInformation_title",
|
|
@@ -187,6 +188,7 @@ var BaseInformation = function (props) {
|
|
|
187
188
|
React.createElement(form_item_1.default, { shouldUpdate: true, dependencies: [["invoice", "orderReference", "documentNo"]], receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.buyerReference, defaultLabel: props.intl.formatMessage(translationMessages.baseInformation_buyerReferenceLabel), defaultLabelTooltip: props.intl.formatMessage(translationMessages.baseInformation_buyerReferenceLabel_helpText), defaultIsRequired: !(props.form.getFieldValue(["invoice", "orderReference", "documentNo"])), fieldName: ["invoice", "buyerReference"] },
|
|
188
189
|
React.createElement(antd_1.Input, null)),
|
|
189
190
|
React.createElement(ReferenceIdentifiers_1.default, { receiverRequirements: props.receiverRequirements, formInstance: props.form, updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, rapiBaseUrl: props.rapiBaseUrl, legalIdentifier: props.legalIdentifier, referenceIdentifiersLabelText: props.referenceIdentifiersLabelText, referenceIdentifiersHelpText: props.referenceIdentifiersHelpText, referenceIdentifierValidateStatus: props.referenceIdentifierValidateStatus, setReferenceIdentifierValidateStatus: props.setReferenceIdentifierValidateStatus }),
|
|
191
|
+
React.createElement(AccountingCost_1.default, { formInstance: props.form, rapiBaseUrl: props.rapiBaseUrl, receiverRequirements: props.receiverRequirements, updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, legalIdentifier: props.legalIdentifier }),
|
|
190
192
|
React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.notes, defaultLabel: props.intl.formatMessage(translationMessages.baseInformation_notes), defaultIsRequired: false, fieldName: ["invoice", "notes"] },
|
|
191
193
|
React.createElement(antd_1.Input.TextArea, null)),
|
|
192
194
|
React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.currencyCode, defaultLabel: props.intl.formatMessage(translationMessages.baseInformation_currencyCode), defaultIsRequired: true, fieldName: ["invoice", "currencyCode"], initialValue: getCurrencies(props.receiverRequirements)[0].key },
|
|
@@ -66,6 +66,10 @@ var translationMessages = react_intl_1.defineMessages({
|
|
|
66
66
|
id: "billingLines_discount",
|
|
67
67
|
defaultMessage: "Discount"
|
|
68
68
|
},
|
|
69
|
+
billingLines_discount_helpText: {
|
|
70
|
+
id: "billingLines_discount_helpText",
|
|
71
|
+
defaultMessage: "Discount can be represented as an amount or a percentage indicated with a percentage sign (%)"
|
|
72
|
+
},
|
|
69
73
|
billingLines_lineAmount: {
|
|
70
74
|
id: "billingLines_lineAmount",
|
|
71
75
|
defaultMessage: "Amount"
|
|
@@ -141,7 +145,7 @@ var BillingLines = function (props) {
|
|
|
141
145
|
return (react_1.default.createElement(antd_1.Select.Option, { disabled: getTaxCategoryDisabled(mapi_1.TaxCategoryTypeEnum[taxCategoryType], props.outsideVatScope), value: taxCategoryType, title: taxCategoryType, key: taxCategoryType }, props.intl.formatMessage(editable_cell_1.commonTranslationMessages["taxCategoryType_labels_" + taxCategoryType]) + " (" + taxPercentage + "%)"));
|
|
142
146
|
})))),
|
|
143
147
|
react_1.default.createElement(antd_1.Col, { span: 2 },
|
|
144
|
-
react_1.default.createElement(form_item_1.default, { className: "umz_noValidationMessage", receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["invoiceLines.discountValue"], defaultIsRequired: false, fieldName: [field.name, "discountValue"], defaultLabel: props.intl.formatMessage(translationMessages.billingLines_discount), verticalLabels: true, onlyLabelOnFirstInList: true, index: index }, BillingLineUtility_1.getCorrectInputNode("discountValue", props.intl))),
|
|
148
|
+
react_1.default.createElement(form_item_1.default, { className: "umz_noValidationMessage", receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["invoiceLines.discountValue"], defaultIsRequired: false, fieldName: [field.name, "discountValue"], defaultLabel: props.intl.formatMessage(translationMessages.billingLines_discount), verticalLabels: true, onlyLabelOnFirstInList: true, index: index, defaultLabelTooltip: props.intl.formatMessage(translationMessages.billingLines_discount_helpText) }, BillingLineUtility_1.getCorrectInputNode("discountValue", props.intl))),
|
|
145
149
|
react_1.default.createElement(antd_1.Col, { span: 2 },
|
|
146
150
|
react_1.default.createElement(form_item_1.default, { className: "umz_noValidationMessage", receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["invoiceLines.taxableAmount"], defaultIsRequired: false, fieldName: [field.name, "taxableAmount"], defaultLabel: props.intl.formatMessage(translationMessages.billingLines_lineAmount), verticalLabels: true, onlyLabelOnFirstInList: true, index: index }, IntlUtility_1.icelandicNumberLocaleWorkaroundChrome(getTaxableAmount(), props.intl))),
|
|
147
151
|
react_1.default.createElement(antd_1.Col, { span: 3 },
|
|
@@ -22,7 +22,7 @@ interface Props extends InjectedIntlProps, FormItemProps {
|
|
|
22
22
|
onlyLabelOnFirstInList?: boolean;
|
|
23
23
|
index?: number;
|
|
24
24
|
}
|
|
25
|
-
declare const _default: React.ComponentClass<Pick<Props, "normalize" | "required" | "label" | "style" | "help" | "children" | "name" | "validateTrigger" | "dependencies" | "getValueFromEvent" | "rules" | "shouldUpdate" | "trigger" | "validateFirst" | "valuePropName" | "getValueProps" | "messageVariables" | "initialValue" | "onReset" | "className" | "id" | "prefixCls" | "isListField" | "colon" | "extra" | "htmlFor" | "index" | "fieldName" | "
|
|
25
|
+
declare const _default: React.ComponentClass<Pick<Props, "normalize" | "required" | "label" | "style" | "help" | "children" | "name" | "validateTrigger" | "dependencies" | "getValueFromEvent" | "rules" | "shouldUpdate" | "trigger" | "validateFirst" | "valuePropName" | "getValueProps" | "messageVariables" | "initialValue" | "onReset" | "className" | "id" | "prefixCls" | "isListField" | "colon" | "extra" | "htmlFor" | "index" | "fieldName" | "noStyle" | "hasFeedback" | "validateStatus" | "fieldKey" | "labelAlign" | "labelCol" | "wrapperCol" | "receiverRequirements" | "receiverRequirementsKey" | "defaultLabel" | "defaultLabelTooltip" | "defaultIsRequired" | "additionalRules" | "verticalLabels" | "onlyLabelOnFirstInList">, any> & {
|
|
26
26
|
WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
|
|
27
27
|
};
|
|
28
28
|
export default _default;
|
|
@@ -66,6 +66,7 @@ var translationMessages = react_intl_1.defineMessages({
|
|
|
66
66
|
* @component
|
|
67
67
|
*/
|
|
68
68
|
var CreateInvoiceConstructor = function (props) {
|
|
69
|
+
var recaptchaRef = react_1.default.useRef(null);
|
|
69
70
|
var intl = props.intl;
|
|
70
71
|
var form = antd_1.Form.useForm()[0];
|
|
71
72
|
var _a = react_1.useState(false), submitting = _a[0], setSubmitting = _a[1];
|
|
@@ -75,6 +76,14 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
75
76
|
var _e = react_1.default.useState(""), referenceIdentifierValidateStatus = _e[0], setReferenceIdentifierValidateStatus = _e[1];
|
|
76
77
|
// const [billingLinesEditableIndex, setBillingLinesEditableIndex] = useState<number>(1)
|
|
77
78
|
var _f = react_1.useState(false), outsideVatScope = _f[0], setOutsideVatScope = _f[1];
|
|
79
|
+
// attachments
|
|
80
|
+
// TODO: remove the states, set the values to the form in attachment components
|
|
81
|
+
var _g = react_1.useState([]), file1 = _g[0], setFile1 = _g[1];
|
|
82
|
+
var _h = react_1.useState(""), attachmentFieldValidation1 = _h[0], setAttachmentFieldValidation1 = _h[1];
|
|
83
|
+
var _j = react_1.useState([]), file2 = _j[0], setFile2 = _j[1];
|
|
84
|
+
var _k = react_1.useState(""), attachmentFieldValidation2 = _k[0], setAttachmentFieldValidation2 = _k[1];
|
|
85
|
+
var _l = react_1.useState([]), file3 = _l[0], setFile3 = _l[1];
|
|
86
|
+
var _m = react_1.useState(""), attachmentFieldValidation3 = _m[0], setAttachmentFieldValidation3 = _m[1];
|
|
78
87
|
react_1.useEffect(function () {
|
|
79
88
|
form.resetFields([
|
|
80
89
|
["invoice", "supplier", "vatNumber"],
|
|
@@ -98,76 +107,16 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
98
107
|
}
|
|
99
108
|
});
|
|
100
109
|
}, [outsideVatScope]);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// label: props.intl.formatMessage(commonTranslationMessages.unitOfMeasure_labels_Piece)
|
|
110
|
-
// },
|
|
111
|
-
// unitPriceAmount: 0,
|
|
112
|
-
// taxCategoryType: {
|
|
113
|
-
// value: TaxCategoryTypeEnum.OutsideTaxScope,
|
|
114
|
-
// label: `${props.intl.formatMessage(commonTranslationMessages.taxCategoryType_labels_OutsideTaxScope)} (0%)`
|
|
115
|
-
// },
|
|
116
|
-
// discountValue: "0",
|
|
117
|
-
// taxableAmount: 0,
|
|
118
|
-
// taxPercentage: 0
|
|
119
|
-
// };
|
|
120
|
-
// const [billingLinesDataSource, setBillingLinesDataSource] = useState<BillingLineMetadataOverride[]>([{
|
|
121
|
-
// ...initialBillingLineData,
|
|
122
|
-
// key: 0,
|
|
123
|
-
// }])
|
|
124
|
-
// BILLING LINES
|
|
125
|
-
// const handleBillingLinesDelete = (index: number) => {
|
|
126
|
-
// const newDataSource = [...billingLinesDataSource];
|
|
127
|
-
// const indexToDelete = newDataSource.findIndex(billingLine => billingLine.key === index)
|
|
128
|
-
// newDataSource.splice(indexToDelete, 1);
|
|
129
|
-
// setBillingLinesDataSource(newDataSource);
|
|
130
|
-
// };
|
|
131
|
-
//
|
|
132
|
-
// const handleBillingLinesAdd = (billingLineToAdd: BillingLineMetadataOverride) => {
|
|
133
|
-
// setBillingLinesDataSource([...billingLinesDataSource, billingLineToAdd])
|
|
134
|
-
// setBillingLinesEditableIndex(billingLinesEditableIndex + 1)
|
|
135
|
-
// };
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
// const handleBillingLinesSave = (row: BillingLineMetadataOverride, formInstance: FormInstance) => {
|
|
139
|
-
// const newData = [...billingLinesDataSource];
|
|
140
|
-
// const index = newData.findIndex((i) => {
|
|
141
|
-
// return row.key === i.key;
|
|
142
|
-
// });
|
|
143
|
-
//
|
|
144
|
-
// const item = newData[index];
|
|
145
|
-
// newData.splice(index, 1, {
|
|
146
|
-
// ...item,
|
|
147
|
-
// ...row,
|
|
148
|
-
// });
|
|
149
|
-
//
|
|
150
|
-
// const billingLineMetadata = newData.map<BillingLineMetadata>(current => {
|
|
151
|
-
// return {
|
|
152
|
-
// ...current,
|
|
153
|
-
// unitOfMeasure: {
|
|
154
|
-
// unit: Units[current.unitOfMeasure.value],
|
|
155
|
-
// },
|
|
156
|
-
// taxCategoryType: TaxCategoryTypeEnum[current.taxCategoryType.value]
|
|
157
|
-
// }
|
|
158
|
-
// });
|
|
159
|
-
//
|
|
160
|
-
// setBillingLinesDataSource(newData)
|
|
161
|
-
//
|
|
162
|
-
// handleSetBillingLineMetadata(formInstance, billingLineMetadata);
|
|
163
|
-
// };
|
|
164
|
-
// END BILLING LINES
|
|
165
|
-
// const handleSetBillingLineMetadata = (formInstance: FormInstance, billingLineMetadata: BillingLineMetadata[]) => {
|
|
166
|
-
// formInstance.setFieldsValue({
|
|
167
|
-
// "billingLinesMetadata": billingLineMetadata
|
|
168
|
-
// })
|
|
169
|
-
// };
|
|
110
|
+
var resetAttachments = function () {
|
|
111
|
+
setFile1([]);
|
|
112
|
+
setAttachmentFieldValidation1("");
|
|
113
|
+
setFile2([]);
|
|
114
|
+
setAttachmentFieldValidation2("");
|
|
115
|
+
setFile3([]);
|
|
116
|
+
setAttachmentFieldValidation3("");
|
|
117
|
+
};
|
|
170
118
|
var handleSubmit = function (values) {
|
|
119
|
+
// console.log("values at the start of submit", values);
|
|
171
120
|
setSubmitting(true);
|
|
172
121
|
if (referenceIdentifierValidateStatus !== "" && referenceIdentifierValidateStatus !== "success") {
|
|
173
122
|
form.scrollToField(["invoice", "referenceIdentifiers", 0, "value"]);
|
|
@@ -245,7 +194,31 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
245
194
|
_loop_1();
|
|
246
195
|
}
|
|
247
196
|
setSubmitting(false);
|
|
197
|
+
// console.log("values after successful submit", values);
|
|
248
198
|
form.resetFields();
|
|
199
|
+
form.setFields([
|
|
200
|
+
{
|
|
201
|
+
name: ["invoice", "invoiceLines"],
|
|
202
|
+
value: [{}]
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: ["invoice", "supplier"],
|
|
206
|
+
value: values.invoice.supplier,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: ["outsideVatScope"],
|
|
210
|
+
value: !values.invoice.supplier.vatNumber
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: ["attachments"],
|
|
214
|
+
value: {
|
|
215
|
+
file1: { file: undefined, description: undefined },
|
|
216
|
+
file2: { file: undefined, description: undefined },
|
|
217
|
+
file3: { file: undefined, description: undefined },
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
]);
|
|
221
|
+
resetAttachments();
|
|
249
222
|
// Clear the billing line dataSource
|
|
250
223
|
setChosenCustomer(ConversionUtility_1.profileOutputToPartyMetadata(props.customers[0]));
|
|
251
224
|
setChosenCustomerApiKey(props.customers[0].apiKey);
|
|
@@ -280,6 +253,12 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
280
253
|
// tslint:disable-next-line:no-console
|
|
281
254
|
console.log(error.config);
|
|
282
255
|
});
|
|
256
|
+
if (recaptchaRef) {
|
|
257
|
+
if (recaptchaRef.current) {
|
|
258
|
+
recaptchaRef.current.reset();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
setIsSubmitDisabled(true);
|
|
283
262
|
};
|
|
284
263
|
react_1.useEffect(function () {
|
|
285
264
|
getReceiverRequirements();
|
|
@@ -313,7 +292,7 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
313
292
|
});
|
|
314
293
|
setChosenCustomerApiKey(props.customers[0].apiKey);
|
|
315
294
|
}
|
|
316
|
-
var
|
|
295
|
+
var _o = react_1.useState(undefined), billingLinesMetadata = _o[0], setBillingLinesMetadata = _o[1];
|
|
317
296
|
var getBillingLines = function (changedValues, allValues) {
|
|
318
297
|
var invoiceLines = allValues.invoice.invoiceLines;
|
|
319
298
|
if (invoiceLines) {
|
|
@@ -355,7 +334,12 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
355
334
|
referenceIdentifiers: [
|
|
356
335
|
{}
|
|
357
336
|
],
|
|
358
|
-
invoiceLines: [{}]
|
|
337
|
+
invoiceLines: [{}],
|
|
338
|
+
attachments: {
|
|
339
|
+
file1: { file: undefined, description: undefined },
|
|
340
|
+
file2: { file: undefined, description: undefined },
|
|
341
|
+
file3: { file: undefined, description: undefined },
|
|
342
|
+
}
|
|
359
343
|
},
|
|
360
344
|
} }),
|
|
361
345
|
react_1.default.createElement(antd_1.Row, { gutter: [16, 16] },
|
|
@@ -382,10 +366,10 @@ var CreateInvoiceConstructor = function (props) {
|
|
|
382
366
|
react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
|
|
383
367
|
react_1.default.createElement(components_1.PaymentMethod, { receiverRequirements: props.receiverRequirements, formInstance: form })),
|
|
384
368
|
react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 16 } },
|
|
385
|
-
react_1.default.createElement(components_1.Attachments, { formInstance: form, uploadSizeLimit: props.uploadSizeLimit, attachmentTooltipText: props.attachmentTooltipText, languageString: props.language })),
|
|
369
|
+
react_1.default.createElement(components_1.Attachments, { formInstance: form, uploadSizeLimit: props.uploadSizeLimit, attachmentTooltipText: props.attachmentTooltipText, languageString: props.language, file1: file1, setFile1: setFile1, attachmentFieldValidation1: attachmentFieldValidation1, setAttachmentFieldValidation1: setAttachmentFieldValidation1, file2: file2, setFile2: setFile2, attachmentFieldValidation2: attachmentFieldValidation2, setAttachmentFieldValidation2: setAttachmentFieldValidation2, file3: file3, setFile3: setFile3, attachmentFieldValidation3: attachmentFieldValidation3, setAttachmentFieldValidation3: setAttachmentFieldValidation3 })),
|
|
386
370
|
react_1.default.createElement(antd_1.Row, { style: { width: "100%", padding: "8px" }, justify: "end" },
|
|
387
371
|
react_1.default.createElement(antd_1.Col, null,
|
|
388
|
-
react_1.default.createElement(react_google_recaptcha_1.default, { sitekey: "6LdMUdEZAAAAAG--2WEyu8CIRVlv6CzdZIwaQ-zt", onChange: function (token) {
|
|
372
|
+
react_1.default.createElement(react_google_recaptcha_1.default, { ref: recaptchaRef, sitekey: "6LdMUdEZAAAAAG--2WEyu8CIRVlv6CzdZIwaQ-zt", onChange: function (token) {
|
|
389
373
|
setIsSubmitDisabled(!token);
|
|
390
374
|
}, hl: props.language }))),
|
|
391
375
|
react_1.default.createElement(antd_1.Row, { style: { width: "100%", padding: "8px" }, justify: "end" },
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"baseInformation_notes": "Athugasemdir",
|
|
23
23
|
"baseInformation_currencyCode": "Gjaldmiðill",
|
|
24
24
|
"baseInformation_costCenter": "Kostnaðarstöð",
|
|
25
|
+
"baseInformation_accountingCostLabel": "Bókunarlykill",
|
|
26
|
+
"baseInformation_accountingCostLabel_helpText": "Bókunarlykill er kóti gefinn upp af kaupanda, gegnum tölvupóst eða síma eða fenginn beint úr pöntun sem tengist þessum reikningi",
|
|
25
27
|
"billingCalculations_labels_TaxAmountWithoutVat": "Samtals án VSK",
|
|
26
28
|
"billingCalculations_labels_TotalVatAmount": "Samtals VSK upphæð",
|
|
27
29
|
"billingCalculations_labels_TotalAmountWithVat": "Samtals með VSK",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"billingLines_taxCategoryType_title": "Ekki er hægt að leggja virðisauka á vöru nema gefa upp VSK númer",
|
|
47
49
|
"billingLines_taxCategoryPercentage": "Skattprósenta",
|
|
48
50
|
"billingLines_discount": "Afsláttur",
|
|
51
|
+
"billingLines_discount_helpText": "Afslátt má setja fram sem upphæð eða sem hlutfall með því að bæta við prósentutákni (%)",
|
|
49
52
|
"billingLines_lineAmount": "Upphæð",
|
|
50
53
|
"billingLines_taxAmount": "Upphæð með skatti",
|
|
51
54
|
"billingLines_button_addRow": "Bæta við röð",
|
|
@@ -24,6 +24,8 @@ declare const _default: {
|
|
|
24
24
|
"baseInformation_notes": string;
|
|
25
25
|
"baseInformation_currencyCode": string;
|
|
26
26
|
"baseInformation_costCenter": string;
|
|
27
|
+
"baseInformation_accountingCostLabel": string;
|
|
28
|
+
"baseInformation_accountingCostLabel_helpText": string;
|
|
27
29
|
"billingCalculations_labels_TaxAmountWithoutVat": string;
|
|
28
30
|
"billingCalculations_labels_TotalVatAmount": string;
|
|
29
31
|
"billingCalculations_labels_TotalAmountWithVat": string;
|
|
@@ -48,6 +50,7 @@ declare const _default: {
|
|
|
48
50
|
"billingLines_taxCategoryType_title": string;
|
|
49
51
|
"billingLines_taxCategoryPercentage": string;
|
|
50
52
|
"billingLines_discount": string;
|
|
53
|
+
"billingLines_discount_helpText": string;
|
|
51
54
|
"billingLines_lineAmount": string;
|
|
52
55
|
"billingLines_taxAmount": string;
|
|
53
56
|
"billingLines_button_addRow": string;
|
|
@@ -8,4 +8,4 @@ export declare const calculateTaxableAmount: (discountValue: string | null | und
|
|
|
8
8
|
export declare const calculateTaxAmount: (taxableAmount: number, taxPercentage: number) => number;
|
|
9
9
|
export declare const calculateTaxPercentage: (taxCategoryType: TaxCategoryTypeEnum | undefined) => number;
|
|
10
10
|
export declare const generateTaxCategoryLabel: (taxCategoryType: TaxCategoryTypeEnum | undefined, taxCategoryTypeTranslated: string) => string;
|
|
11
|
-
export declare const getCorrectInputNode: (dataIdx: "key" | "name" | "description" | "referenceIdentifiers" | "
|
|
11
|
+
export declare const getCorrectInputNode: (dataIdx: "key" | "name" | "description" | "referenceIdentifiers" | "accountingCost" | "notes" | "billingPeriod" | "unitOfMeasure" | "taxCategoryType" | "itemNo" | "quantity" | "unitPriceAmount" | "taxableAmount" | "taxAmount" | "taxPercentage" | "discountValue" | "discountReason" | "buyersItemNo" | "standardItemNo" | "originCountryCode" | "commodityClassification" | "additionalItemProperties" | "orderLineReference", intl: InjectedIntl) => React.ReactChild;
|
|
@@ -150,7 +150,7 @@ var convertToInvoiceMetadataInput = function (formValues, invoiceLinesWithCalcul
|
|
|
150
150
|
if (resp.invoice && resp.invoice.delivery && resp.invoice.delivery === {}) {
|
|
151
151
|
delete resp.invoice.delivery;
|
|
152
152
|
}
|
|
153
|
-
if (resp.invoice && resp.invoice.orderReference) {
|
|
153
|
+
if (resp.invoice && !resp.invoice.orderReference) {
|
|
154
154
|
delete resp.invoice.orderReference;
|
|
155
155
|
}
|
|
156
156
|
return resp;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { AvailableFields } from "../common/types/ReceiverRequirements";
|
|
3
4
|
import { FieldDefinition, NewReceiverRequirements } from "../common/types/NewReceiverRequirements";
|
|
5
|
+
import { FormItemProps } from "antd/lib/form/FormItem";
|
|
6
|
+
import { FormInstance } from "antd/es/form";
|
|
4
7
|
export declare const getFieldRequirements: (receiverRequirements: NewReceiverRequirements, key: AvailableFields) => FieldDefinition | undefined;
|
|
5
8
|
export declare const getFieldLabelOverride: (receiverRequirements: NewReceiverRequirements, key: AvailableFields, defaultLabel: React.ReactNode) => React.ReactNode;
|
|
6
9
|
export declare const getFieldLabelTooltipOverride: (receiverRequirements: NewReceiverRequirements, key: AvailableFields, defaultLabelTooltip: React.ReactNode) => React.ReactNode;
|
|
7
10
|
export declare const getFieldIsRequired: (receiverRequirements: NewReceiverRequirements, key: AvailableFields, defaultIsRequired: boolean) => boolean;
|
|
11
|
+
export interface FormItemPropsWithoutChildren extends Omit<FormItemProps, "children"> {
|
|
12
|
+
}
|
|
13
|
+
export declare const handleValueValidation: ((isoNumber: string, fieldName: string, value: string, rapiBaseUrl: string, namePath: string | number | (string | number)[], setValidationStatus: (validationStatus: "" | "error" | "success" | "validating" | "warning") => void, formInstance: FormInstance, callName: string) => void) & import("lodash").Cancelable;
|
|
14
|
+
export declare const debouncedHandleSearchValues: ((searchValue: string, fieldDefinition: FieldDefinition, setLoadingValues: (loadingValues: boolean) => void, loadingValues: boolean, receiverRequirements: NewReceiverRequirements, updateReceiverRequirementsProp: (newReceiverRequirements: NewReceiverRequirements) => void, callName: string, rapiBaseUrl: string, overwrittenFieldDefinitionKey?: string | undefined) => void) & import("lodash").Cancelable;
|
|
15
|
+
export declare const getInput: (fieldDefinition: FieldDefinition, namePath: string | number | (string | number)[], validationCallName: string, legalIdentifier: string, formInstance: FormInstance, rapiBaseUrl: string, receiverRequirements: NewReceiverRequirements, updateReceiverRequirementsProp: (receiverRequirements: NewReceiverRequirements) => void, setAccountingCostFieldProps: (accountingCostFiledProps: FormItemPropsWithoutChildren) => void, accountingCostFieldProps: FormItemPropsWithoutChildren, setLoadingAccountingCostValues: (loadingAccountingCostValues: boolean) => void, loadingAccountingCostValues: boolean, setHandlingValidationStatus: (handlingValidationStatus: "" | "error" | "success" | "validating" | "warning") => void) => React.ReactNode;
|
|
@@ -1,5 +1,24 @@
|
|
|
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
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var react_1 = __importDefault(require("react"));
|
|
18
|
+
var lodash_1 = require("lodash");
|
|
19
|
+
var axios_1 = __importDefault(require("axios"));
|
|
20
|
+
var ApiUtility_1 = require("./ApiUtility");
|
|
21
|
+
var antd_1 = require("antd");
|
|
3
22
|
// export const getReceiverRequirements = (recRequirements: ReceiverRequirements, key: AvailableFields): FieldRequirement => {
|
|
4
23
|
// return recRequirements[key]!;
|
|
5
24
|
// };
|
|
@@ -60,3 +79,74 @@ var cardinalityToRequired = function (cardinality) {
|
|
|
60
79
|
throw new Error("Cardinality \"" + cardinality + "\" is not supported");
|
|
61
80
|
}
|
|
62
81
|
};
|
|
82
|
+
exports.handleValueValidation = lodash_1.debounce(function (isoNumber, fieldName, value, rapiBaseUrl, namePath, setValidationStatus, formInstance, callName) {
|
|
83
|
+
if (value.length === 0) {
|
|
84
|
+
setValidationStatus("");
|
|
85
|
+
formInstance.resetFields([namePath]);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
var searchUrl = rapiBaseUrl + ("/api/v1/requirements/" + isoNumber + "/" + fieldName + "/values/validate?value=" + encodeURIComponent(value));
|
|
89
|
+
setValidationStatus("validating");
|
|
90
|
+
axios_1.default.get(searchUrl, { cancelToken: ApiUtility_1.getCancelToken(callName) })
|
|
91
|
+
.then(function (response) {
|
|
92
|
+
response.data ? setValidationStatus("success") : setValidationStatus("error");
|
|
93
|
+
})
|
|
94
|
+
.catch(function (error) {
|
|
95
|
+
setValidationStatus("error");
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, 500);
|
|
99
|
+
var handleValueSearch = function (searchValue, fieldDefinition, setLoadingValues, loadingValues, receiverRequirements, updateReceiverRequirementsProp, callName, rapiBaseUrl, overwrittenFieldDefinitionKey) {
|
|
100
|
+
if (fieldDefinition.properties.href) {
|
|
101
|
+
var searchUrl = rapiBaseUrl + fieldDefinition.properties.href.replace("%7BtextFilter%7D", encodeURIComponent(searchValue)).replace("%7Boffset%7D", "0").replace("%7Blimit%7D", "15");
|
|
102
|
+
if (!loadingValues) {
|
|
103
|
+
setLoadingValues(true);
|
|
104
|
+
}
|
|
105
|
+
axios_1.default.get(searchUrl, { cancelToken: ApiUtility_1.getCancelToken(callName) })
|
|
106
|
+
.then(function (response) {
|
|
107
|
+
setLoadingValues(false);
|
|
108
|
+
var updatedFieldDefinitions = receiverRequirements.fieldDefinitions.slice();
|
|
109
|
+
var key = overwrittenFieldDefinitionKey ? overwrittenFieldDefinitionKey : fieldDefinition.key;
|
|
110
|
+
var index = updatedFieldDefinitions.findIndex(function (x) { return x.key === key; });
|
|
111
|
+
var updatedFieldDefinition = __assign({}, updatedFieldDefinitions[index], { properties: __assign({}, updatedFieldDefinitions[index].properties, { values: response.data.value }) });
|
|
112
|
+
updatedFieldDefinitions.splice(index, 1, updatedFieldDefinition);
|
|
113
|
+
var newReceiverRequirements = __assign({}, receiverRequirements, { fieldDefinitions: updatedFieldDefinitions });
|
|
114
|
+
updateReceiverRequirementsProp(newReceiverRequirements);
|
|
115
|
+
})
|
|
116
|
+
.catch(function (error) {
|
|
117
|
+
setLoadingValues(false);
|
|
118
|
+
// tslint:disable-next-line:no-console
|
|
119
|
+
console.log(error);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
exports.debouncedHandleSearchValues = lodash_1.debounce(handleValueSearch, 500);
|
|
124
|
+
exports.getInput = function (fieldDefinition, namePath, validationCallName, legalIdentifier, formInstance, rapiBaseUrl, receiverRequirements, updateReceiverRequirementsProp, setAccountingCostFieldProps, accountingCostFieldProps, setLoadingAccountingCostValues, loadingAccountingCostValues, setHandlingValidationStatus) {
|
|
125
|
+
var handling = null;
|
|
126
|
+
if (fieldDefinition.properties.handling) {
|
|
127
|
+
handling = JSON.parse(fieldDefinition.properties.handling);
|
|
128
|
+
}
|
|
129
|
+
if (handling && handling.shouldBeValidated) {
|
|
130
|
+
return (react_1.default.createElement(antd_1.Input, { onBlur: function (event) {
|
|
131
|
+
exports.handleValueValidation(legalIdentifier, fieldDefinition.name, event.currentTarget.value, rapiBaseUrl, namePath, setHandlingValidationStatus, formInstance, validationCallName);
|
|
132
|
+
} }));
|
|
133
|
+
}
|
|
134
|
+
else if (fieldDefinition.properties.values) {
|
|
135
|
+
var selectProps = fieldDefinition.properties.hasOwnProperty("href")
|
|
136
|
+
? {
|
|
137
|
+
showSearch: true,
|
|
138
|
+
filterOption: false,
|
|
139
|
+
onSearch: function (searchValue) {
|
|
140
|
+
exports.debouncedHandleSearchValues(searchValue, fieldDefinition, setLoadingAccountingCostValues, loadingAccountingCostValues, receiverRequirements, updateReceiverRequirementsProp, "getAccountingCOstValues", rapiBaseUrl);
|
|
141
|
+
},
|
|
142
|
+
loading: loadingAccountingCostValues,
|
|
143
|
+
}
|
|
144
|
+
: {};
|
|
145
|
+
return (react_1.default.createElement(antd_1.Select, __assign({ dropdownMatchSelectWidth: false }, selectProps), fieldDefinition.properties.values.map(function (op) {
|
|
146
|
+
return react_1.default.createElement(antd_1.Select.Option, { key: op.key, value: op.key }, op.name);
|
|
147
|
+
})));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return (react_1.default.createElement(antd_1.Input, null));
|
|
151
|
+
}
|
|
152
|
+
};
|