@unimaze/billing 0.12.7 → 0.12.12

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.
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import { InjectedIntlProps } from "react-intl";
3
3
  import { NewReceiverRequirements } from "../../types/NewReceiverRequirements";
4
4
  import { FormInstance } from "antd/es/form";
5
+ import { ValidateStatus } from "antd/lib/form/FormItem";
5
6
  export declare const translationMessages: ReactIntl.Messages<"referenceIdentifiers_labels_addButton" | "referenceIdentifiers_labels_referenceIdentifier" | "referenceIdentifiers_labels_referenceIdentifier_title" | "referenceIdentifiers_labels_AKY" | "referenceIdentifiers_labels_ARR" | "referenceIdentifiers_labels_LOC">;
6
7
  interface Props extends InjectedIntlProps {
7
8
  receiverRequirements: NewReceiverRequirements;
@@ -11,8 +12,10 @@ interface Props extends InjectedIntlProps {
11
12
  legalIdentifier: string;
12
13
  referenceIdentifiersLabelText?: string;
13
14
  referenceIdentifiersHelpText?: string;
15
+ referenceIdentifierValidateStatus: ValidateStatus;
16
+ setReferenceIdentifierValidateStatus: (referenceIdentifierValidateStatus: ValidateStatus) => void;
14
17
  }
15
- declare const _default: React.ComponentClass<Pick<Props, "formInstance" | "receiverRequirements" | "updateReceiverRequirementsProp" | "rapiBaseUrl" | "legalIdentifier" | "referenceIdentifiersLabelText" | "referenceIdentifiersHelpText">, any> & {
18
+ declare const _default: React.ComponentClass<Pick<Props, "formInstance" | "receiverRequirements" | "updateReceiverRequirementsProp" | "rapiBaseUrl" | "legalIdentifier" | "referenceIdentifiersLabelText" | "referenceIdentifiersHelpText" | "referenceIdentifierValidateStatus" | "setReferenceIdentifierValidateStatus">, any> & {
16
19
  WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
17
20
  };
18
21
  export default _default;
@@ -57,9 +57,8 @@ exports.translationMessages = react_intl_1.defineMessages({
57
57
  },
58
58
  });
59
59
  var ReferenceIdentifiers = function (props) {
60
- var _a = react_1.default.useState(""), validateStatus = _a[0], setValidateStatus = _a[1];
61
- var _b = react_1.useState([]), referenceIdentifierValue = _b[0], setReferenceIdentifierValue = _b[1];
62
- var _c = react_1.useState(false), loadingReferenceIdentifierValues = _c[0], setLoadingReferenceIdentifierValues = _c[1]; // TODO: change this to boolean[] for handling the list
60
+ var _a = react_1.useState([]), referenceIdentifierValue = _a[0], setReferenceIdentifierValue = _a[1];
61
+ var _b = react_1.useState(false), loadingReferenceIdentifierValues = _b[0], setLoadingReferenceIdentifierValues = _b[1]; // TODO: change this to boolean[] for handling the list
63
62
  var referenceIdentifiersHelp = props.referenceIdentifiersHelpText ? props.referenceIdentifiersHelpText : props.intl.formatMessage(exports.translationMessages.referenceIdentifiers_labels_referenceIdentifier_title);
64
63
  var referenceIdentifiersLabel = props.referenceIdentifiersLabelText ? props.referenceIdentifiersLabelText : props.intl.formatMessage(exports.translationMessages.referenceIdentifiers_labels_referenceIdentifier);
65
64
  var referenceIdentifierOptions = ReferenceIdentifierUtility_1.getReferenceIdentifierOptions(props.receiverRequirements);
@@ -117,20 +116,26 @@ var ReferenceIdentifiers = function (props) {
117
116
  });
118
117
  }
119
118
  }, 500);
120
- var handleReferenceIdentifierValueValidation = lodash_1.debounce(function (isoNumber, fieldName, value, rapiBaseUrl) {
121
- var searchUrl = rapiBaseUrl + ("/api/v1/requirements/" + isoNumber + "/" + fieldName + "/values/validate?value=" + encodeURIComponent(value));
122
- setValidateStatus("validating");
123
- axios_1.default.get(searchUrl, { cancelToken: ApiUtility_1.getCancelToken("referenceIdentifierValueValidation") })
124
- .then(function (response) {
125
- response.data ? setValidateStatus("success") : setValidateStatus("error");
126
- })
127
- .catch(function (error) {
128
- // tslint:disable-next-line:no-console
129
- console.log(error);
130
- setValidateStatus("error");
131
- });
119
+ var handleReferenceIdentifierValueValidation = lodash_1.debounce(function (isoNumber, fieldName, value, rapiBaseUrl, namePath, setReferenceIdentifierValidateStatus) {
120
+ if (value.length === 0) {
121
+ setReferenceIdentifierValidateStatus("");
122
+ props.formInstance.resetFields([namePath]);
123
+ }
124
+ else {
125
+ var searchUrl = rapiBaseUrl + ("/api/v1/requirements/" + isoNumber + "/" + fieldName + "/values/validate?value=" + encodeURIComponent(value));
126
+ setReferenceIdentifierValidateStatus("validating");
127
+ axios_1.default.get(searchUrl, { cancelToken: ApiUtility_1.getCancelToken("referenceIdentifierValueValidation") })
128
+ .then(function (response) {
129
+ response.data ? setReferenceIdentifierValidateStatus("success") : setReferenceIdentifierValidateStatus("error");
130
+ })
131
+ .catch(function (error) {
132
+ // tslint:disable-next-line:no-console
133
+ console.log(error);
134
+ setReferenceIdentifierValidateStatus("error");
135
+ });
136
+ }
132
137
  }, 500);
133
- var getReferenceIdentifierValueFormItemInput = function (value, receiverRequirements, rapiBaseUrl, legalIdentifier, field) {
138
+ var getReferenceIdentifierValueFormItemInput = function (value, receiverRequirements, rapiBaseUrl, legalIdentifier, field, referenceIdentifierValidateStatus, setReferenceIdentifierValidateStatus) {
134
139
  var fieldProps = __assign({}, field, { name: [field.name, "value"],
135
140
  // fieldKey: [field.fieldKey, "value"],
136
141
  rules: [{ required: false }] });
@@ -143,9 +148,9 @@ var ReferenceIdentifiers = function (props) {
143
148
  fieldHandling = JSON.parse(fieldDefinition_1.properties.handling);
144
149
  }
145
150
  if (fieldHandling && fieldHandling.shouldBeValidated) {
146
- fieldProps = __assign({}, fieldProps, { validateStatus: validateStatus, hasFeedback: true });
151
+ fieldProps = __assign({}, fieldProps, { validateStatus: referenceIdentifierValidateStatus, hasFeedback: true });
147
152
  return (react_1.default.createElement(antd_1.Form.Item, __assign({}, fieldProps),
148
- react_1.default.createElement(antd_1.Input, { onBlur: function (event) { return handleReferenceIdentifierValueValidation(legalIdentifier, fieldDefinition_1.name, event.currentTarget.value, rapiBaseUrl); } })));
153
+ react_1.default.createElement(antd_1.Input, { onBlur: function (event) { return handleReferenceIdentifierValueValidation(legalIdentifier, fieldDefinition_1.name, event.currentTarget.value, rapiBaseUrl, ["invoice", "referenceIdentifiers", field.name, "value"], setReferenceIdentifierValidateStatus); } })));
149
154
  }
150
155
  if (fieldDefinition_1.properties.hasOwnProperty("values") && fieldDefinition_1.properties.values /*&& fieldDefinition.properties.values.length > 0*/) {
151
156
  var selectProps = fieldDefinition_1.properties.hasOwnProperty("href")
@@ -194,8 +199,8 @@ var ReferenceIdentifiers = function (props) {
194
199
  react_1.default.createElement(icons_1.QuestionCircleOutlined, null))))
195
200
  : singleReferenceIdentifierLabel;
196
201
  if (fieldHandling && fieldHandling.shouldBeValidated) {
197
- return (react_1.default.createElement(antd_1.Form.Item, { name: ["invoice", "referenceIdentifiers", "0", "value"], label: singleReferenceIdentifierLabelNode, validateStatus: validateStatus, hasFeedback: true },
198
- react_1.default.createElement(antd_1.Input, { onBlur: function (event) { return handleReferenceIdentifierValueValidation(props.legalIdentifier, fieldDefinition.name, event.currentTarget.value, props.rapiBaseUrl); } })));
202
+ return (react_1.default.createElement(antd_1.Form.Item, { name: ["invoice", "referenceIdentifiers", "0", "value"], label: singleReferenceIdentifierLabelNode, validateStatus: props.referenceIdentifierValidateStatus, hasFeedback: true },
203
+ react_1.default.createElement(antd_1.Input, { onBlur: function (event) { return handleReferenceIdentifierValueValidation(props.legalIdentifier, fieldDefinition.name, event.currentTarget.value, props.rapiBaseUrl, ["invoice", "referenceIdentifiers", "0", "value"], props.setReferenceIdentifierValidateStatus); } })));
199
204
  }
200
205
  if (fieldDefinition.properties.hasOwnProperty("values") && fieldDefinition.properties.values) {
201
206
  var selectProps = fieldDefinition.properties.hasOwnProperty("href")
@@ -248,10 +253,10 @@ var ReferenceIdentifiers = function (props) {
248
253
  var newState = referenceIdentifierValue.slice();
249
254
  newState.splice(index, 1, a);
250
255
  setReferenceIdentifierValue(newState);
251
- setValidateStatus("");
256
+ props.setReferenceIdentifierValidateStatus("");
252
257
  props.formInstance.resetFields([["invoice", "referenceIdentifiers", index, "value"]]);
253
258
  } }, getReferenceIdentifier(props.receiverRequirements)))),
254
- react_1.default.createElement(antd_1.Col, { span: 12 }, getReferenceIdentifierValueFormItemInput(referenceIdentifierValue[index], props.receiverRequirements, props.rapiBaseUrl, props.legalIdentifier, field)))));
259
+ react_1.default.createElement(antd_1.Col, { span: 12 }, getReferenceIdentifierValueFormItemInput(referenceIdentifierValue[index], props.receiverRequirements, props.rapiBaseUrl, props.legalIdentifier, field, props.referenceIdentifierValidateStatus, props.setReferenceIdentifierValidateStatus)))));
255
260
  }));
256
261
  }));
257
262
  };
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  import { FormInstance } from "antd/es/form";
3
3
  import { InjectedIntlProps } from "react-intl";
4
4
  import { NewReceiverRequirements } from "../../types/NewReceiverRequirements";
5
+ import { ValidateStatus } from "antd/lib/form/FormItem";
5
6
  interface Props extends InjectedIntlProps {
6
7
  receiverRequirements: NewReceiverRequirements;
7
8
  form: FormInstance;
@@ -11,8 +12,10 @@ interface Props extends InjectedIntlProps {
11
12
  legalIdentifier: string;
12
13
  referenceIdentifiersLabelText?: string;
13
14
  referenceIdentifiersHelpText?: string;
15
+ referenceIdentifierValidateStatus: ValidateStatus;
16
+ setReferenceIdentifierValidateStatus: (referenceIdentifierValidateStatus: ValidateStatus) => void;
14
17
  }
15
- declare const BaseInformationIntl: React.ComponentClass<Pick<Props, "form" | "receiverRequirements" | "updateReceiverRequirementsProp" | "rapiBaseUrl" | "legalIdentifier" | "referenceIdentifiersLabelText" | "referenceIdentifiersHelpText" | "documentType">, any> & {
18
+ declare const BaseInformationIntl: React.ComponentClass<Pick<Props, "form" | "receiverRequirements" | "updateReceiverRequirementsProp" | "rapiBaseUrl" | "legalIdentifier" | "referenceIdentifiersLabelText" | "referenceIdentifiersHelpText" | "referenceIdentifierValidateStatus" | "setReferenceIdentifierValidateStatus" | "documentType">, any> & {
16
19
  WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
17
20
  };
18
21
  export default BaseInformationIntl;
@@ -186,7 +186,7 @@ var BaseInformation = function (props) {
186
186
  React.createElement(OrderReference_1.default, { receiverRequirements: props.receiverRequirements, formInstance: props.form, dependencies: [["invoice", "buyerReference"]] }),
187
187
  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
188
  React.createElement(antd_1.Input, null)),
189
- 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 }),
189
+ 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 }),
190
190
  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
191
  React.createElement(antd_1.Input.TextArea, null)),
192
192
  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 },
@@ -64,7 +64,7 @@ var translationMessages = react_intl_1.defineMessages({
64
64
  },
65
65
  supplier_contact_email: {
66
66
  id: "supplier_contact_email",
67
- defaultMessage: "E-Mail"
67
+ defaultMessage: "E-mail"
68
68
  },
69
69
  supplier_contact_email_title: {
70
70
  id: "supplier_contact_email_title",
@@ -28,6 +28,7 @@ var components_1 = require("../common/components");
28
28
  // }
29
29
  // );
30
30
  var form = antd_1.Form.useForm()[0];
31
+ var _a = react_1.default.useState(""), referenceIdentifierValidateStatus = _a[0], setReferenceIdentifierValidateStatus = _a[1];
31
32
  var handleSetBillingLineMetadata = function (formInstance, billingLineMetadata) {
32
33
  formInstance.setFieldsValue({
33
34
  "billingLineMetadata": billingLineMetadata,
@@ -54,7 +55,7 @@ var CreateInvoice = function (props) {
54
55
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 }, xl: { span: 12 } }),
55
56
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 }, xl: { span: 12 } }),
56
57
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 }, xl: { span: 8 } },
57
- react_1.default.createElement(components_1.BaseInformation, { receiverRequirements: props.receiverRequirements, form: form, documentType: "creditNote", updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, rapiBaseUrl: props.rapiBaseUrl, legalIdentifier: props.legalIdentifier })),
58
+ react_1.default.createElement(components_1.BaseInformation, { receiverRequirements: props.receiverRequirements, form: form, documentType: "creditNote", updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, rapiBaseUrl: props.rapiBaseUrl, legalIdentifier: props.legalIdentifier, referenceIdentifierValidateStatus: referenceIdentifierValidateStatus, setReferenceIdentifierValidateStatus: setReferenceIdentifierValidateStatus })),
58
59
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 24 }, xl: { span: 16 } }),
59
60
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 24 }, xl: { span: 24 } }),
60
61
  react_1.default.createElement(antd_1.Col, { span: 24 },
@@ -72,8 +72,9 @@ var CreateInvoiceConstructor = function (props) {
72
72
  var _b = react_1.useState(true), isSubmitDisabled = _b[0], setIsSubmitDisabled = _b[1];
73
73
  var _c = react_1.useState(ConversionUtility_1.profileOutputToPartyMetadata(props.customers[0])), chosenCustomer = _c[0], setChosenCustomer = _c[1];
74
74
  var _d = react_1.useState(props.customers[0].apiKey), chosenCustomerApiKey = _d[0], setChosenCustomerApiKey = _d[1];
75
+ var _e = react_1.default.useState(""), referenceIdentifierValidateStatus = _e[0], setReferenceIdentifierValidateStatus = _e[1];
75
76
  // const [billingLinesEditableIndex, setBillingLinesEditableIndex] = useState<number>(1)
76
- var _e = react_1.useState(false), outsideVatScope = _e[0], setOutsideVatScope = _e[1];
77
+ var _f = react_1.useState(false), outsideVatScope = _f[0], setOutsideVatScope = _f[1];
77
78
  react_1.useEffect(function () {
78
79
  form.resetFields([
79
80
  ["invoice", "supplier", "vatNumber"],
@@ -168,6 +169,11 @@ var CreateInvoiceConstructor = function (props) {
168
169
  // };
169
170
  var handleSubmit = function (values) {
170
171
  setSubmitting(true);
172
+ if (referenceIdentifierValidateStatus !== "" && referenceIdentifierValidateStatus !== "success") {
173
+ form.scrollToField(["invoice", "referenceIdentifiers", 0, "value"]);
174
+ setSubmitting(false);
175
+ return;
176
+ }
171
177
  var attachments = [
172
178
  values.attachments.file1 && values.attachments.file1,
173
179
  values.attachments.file2 && values.attachments.file2,
@@ -307,7 +313,7 @@ var CreateInvoiceConstructor = function (props) {
307
313
  });
308
314
  setChosenCustomerApiKey(props.customers[0].apiKey);
309
315
  }
310
- var _f = react_1.useState(undefined), billingLinesMetadata = _f[0], setBillingLinesMetadata = _f[1];
316
+ var _g = react_1.useState(undefined), billingLinesMetadata = _g[0], setBillingLinesMetadata = _g[1];
311
317
  var getBillingLines = function (changedValues, allValues) {
312
318
  var invoiceLines = allValues.invoice.invoiceLines;
313
319
  if (invoiceLines) {
@@ -360,7 +366,7 @@ var CreateInvoiceConstructor = function (props) {
360
366
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
361
367
  react_1.default.createElement(components_1.Customer, { receiverRequirements: props.receiverRequirements, formInstance: form, customers: props.customers, chosenCustomer: chosenCustomer, setChosenCustomer: setChosenCustomer, setChosenCustomerApiKey: setChosenCustomerApiKey, rapiBaseUrl: props.rapiBaseUrl, updateReceiverRequirementsProp: props.updateReceiverRequirementsProp })),
362
368
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
363
- react_1.default.createElement(components_1.BaseInformation, { receiverRequirements: props.receiverRequirements, form: form, documentType: "invoice", updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, rapiBaseUrl: props.rapiBaseUrl, legalIdentifier: chosenCustomer.identifier, referenceIdentifiersLabelText: props.referenceIdentifiersLabelText, referenceIdentifiersHelpText: props.referenceIdentifiersHelpText })),
369
+ react_1.default.createElement(components_1.BaseInformation, { receiverRequirements: props.receiverRequirements, form: form, documentType: "invoice", updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, rapiBaseUrl: props.rapiBaseUrl, legalIdentifier: chosenCustomer.identifier, referenceIdentifiersLabelText: props.referenceIdentifiersLabelText, referenceIdentifiersHelpText: props.referenceIdentifiersHelpText, referenceIdentifierValidateStatus: referenceIdentifierValidateStatus, setReferenceIdentifierValidateStatus: setReferenceIdentifierValidateStatus })),
364
370
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 24 } },
365
371
  react_1.default.createElement(components_1.BillingLines
366
372
  // setBillingLineMetadata={handleSetBillingLineMetadata}
@@ -96,6 +96,9 @@ var convertToInvoiceMetadataInput = function (formValues, invoiceLinesWithCalcul
96
96
  };
97
97
  };
98
98
  var vatNumber = invoice.supplier.vatNumber ? invoice.supplier.vatNumber : "";
99
+ var orderReference = invoice.orderReference && invoice.orderReference.hasOwnProperty("documentNo")
100
+ ? invoice.orderReference
101
+ : undefined;
99
102
  var resp = {
100
103
  messageHandling: getMessageHandling(chosenCustomer),
101
104
  invoice: {
@@ -141,12 +144,15 @@ var convertToInvoiceMetadataInput = function (formValues, invoiceLinesWithCalcul
141
144
  buyerReference: invoice.buyerReference,
142
145
  paymentMeans: paymentMethod,
143
146
  referenceIdentifiers: referenceIdentifiers,
144
- orderReference: invoice.orderReference,
147
+ orderReference: orderReference,
145
148
  }
146
149
  };
147
150
  if (resp.invoice && resp.invoice.delivery && resp.invoice.delivery === {}) {
148
151
  delete resp.invoice.delivery;
149
152
  }
153
+ if (resp.invoice && resp.invoice.orderReference) {
154
+ delete resp.invoice.orderReference;
155
+ }
150
156
  return resp;
151
157
  };
152
158
  exports.convertToInvoiceMetadataInput = convertToInvoiceMetadataInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unimaze/billing",
3
- "version": "0.12.7",
3
+ "version": "0.12.12",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",