@unimaze/billing 0.13.2 → 0.15.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 (44) hide show
  1. package/lib/common/components/base-information/CostCenter.d.ts +12 -0
  2. package/lib/common/components/base-information/CostCenter.js +107 -0
  3. package/lib/common/components/base-information/index.js +24 -11
  4. package/lib/common/types/ReceiverRequirements.d.ts +1 -0
  5. package/lib/common/types/ReceiverRequirements.js +1 -0
  6. package/lib/create-invoice/CreateInvoiceConstructor.d.ts +11 -0
  7. package/lib/create-invoice/CreateInvoiceConstructor.js +213 -0
  8. package/lib/create-invoice/index.js +45 -15
  9. package/lib/example/src/index.d.ts +1 -0
  10. package/lib/src/common/components/attachments/Attachment.d.ts +18 -0
  11. package/lib/src/common/components/attachments/index.d.ts +6 -0
  12. package/lib/src/common/components/base-information/ReferenceIdentifiers.d.ts +17 -0
  13. package/lib/src/common/components/base-information/index.d.ts +11 -0
  14. package/lib/src/common/components/billing-lines/BillingCalculations.d.ts +11 -0
  15. package/lib/src/common/components/billing-lines/BillingTaxSummary.d.ts +10 -0
  16. package/lib/src/common/components/billing-lines/index.d.ts +19 -0
  17. package/lib/src/common/components/component-container/Content.d.ts +7 -0
  18. package/lib/src/common/components/component-container/Header.d.ts +9 -0
  19. package/lib/src/common/components/component-container/index.d.ts +10 -0
  20. package/lib/src/common/components/customer/index.d.ts +15 -0
  21. package/lib/src/common/components/delivery-location/index.d.ts +6 -0
  22. package/lib/src/common/components/editable-cell/index.d.ts +11 -0
  23. package/lib/src/common/components/editable-row/index.d.ts +5 -0
  24. package/lib/src/common/components/form-item/index.d.ts +23 -0
  25. package/lib/src/common/components/index.d.ts +10 -0
  26. package/lib/src/common/components/locale-intl/index.d.ts +10 -0
  27. package/lib/src/common/components/payment-method/index.d.ts +6 -0
  28. package/lib/src/common/components/payment-method/paymentMethodForConversion.d.ts +9 -0
  29. package/lib/src/common/components/supplier/index.d.ts +10 -0
  30. package/lib/src/common/consts/formLayout.d.ts +44 -0
  31. package/lib/src/common/consts/validationRules.d.ts +6 -0
  32. package/lib/src/common/types/ReceiverRequirements.d.ts +81 -0
  33. package/lib/src/create-invoice/index.d.ts +14 -0
  34. package/lib/src/translations/locales.d.ts +77 -0
  35. package/lib/src/utils/ApiUtility.d.ts +21 -0
  36. package/lib/src/utils/BillingLineUtility.d.ts +10 -0
  37. package/lib/src/utils/ConversionUtility.d.ts +8 -0
  38. package/lib/src/utils/RequirementsUtility.d.ts +5 -0
  39. package/lib/src/utils/index.d.ts +2 -0
  40. package/lib/style/index.css +50 -50
  41. package/lib/translations/locales/is.json +3 -0
  42. package/lib/translations/locales.d.ts +3 -0
  43. package/lib/utils/ConversionUtility.js +7 -0
  44. package/package.json +2 -3
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { InjectedIntlProps } from "react-intl";
3
+ import { NewReceiverRequirements } from "../../types/NewReceiverRequirements";
4
+ interface Props extends InjectedIntlProps {
5
+ receiverRequirements: NewReceiverRequirements;
6
+ updateReceiverRequirementsProp: (receiverRequirements: NewReceiverRequirements) => void;
7
+ rapiBaseUrl: string;
8
+ }
9
+ declare const _default: React.ComponentClass<Pick<Props, "receiverRequirements" | "updateReceiverRequirementsProp" | "rapiBaseUrl">, any> & {
10
+ WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
11
+ };
12
+ export default _default;
@@ -0,0 +1,107 @@
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 __importStar = (this && this.__importStar) || function (mod) {
14
+ if (mod && mod.__esModule) return mod;
15
+ var result = {};
16
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
17
+ result["default"] = mod;
18
+ return result;
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ var react_1 = __importStar(require("react"));
25
+ var ReceiverRequirements_1 = require("../../types/ReceiverRequirements");
26
+ var antd_1 = require("antd");
27
+ var form_item_1 = __importDefault(require("../form-item"));
28
+ var react_intl_1 = require("react-intl");
29
+ var axios_1 = __importDefault(require("axios"));
30
+ // import {FormInstance} from "antd/es/form";
31
+ var translationMessages = {
32
+ baseInformation_costCenter: {
33
+ id: "baseInformation_costCenter",
34
+ defaultMessage: "Cost center",
35
+ },
36
+ };
37
+ var getCostCenterFieldDefinitions = function (receiverRequirements) {
38
+ return receiverRequirements && receiverRequirements.fieldDefinitions.find(function (fieldRequirement) { return fieldRequirement.key === "customer.locationIdentifier"; });
39
+ };
40
+ var handleReferenceIdentifierValueSearch = function (searchValue, costCenterFieldDefinition, receiverRequirements, rapiBaseUrl, setLoadingCostCenterValues, updateReceiverRequirementsProp) {
41
+ if (costCenterFieldDefinition.properties.href) {
42
+ var searchUrl = rapiBaseUrl + costCenterFieldDefinition.properties.href.replace("%7BtextFilter%7D", searchValue).replace("%7Boffset%7D", "0").replace("%7Blimit%7D", "15");
43
+ setLoadingCostCenterValues(true);
44
+ axios_1.default.get(searchUrl)
45
+ .then(function (response) {
46
+ setLoadingCostCenterValues(false);
47
+ var updatedFieldDefinitions = receiverRequirements.fieldDefinitions.slice();
48
+ var index = updatedFieldDefinitions.findIndex(function (x) { return x.key === costCenterFieldDefinition.key; });
49
+ var updatedReferenceIdentifier = __assign({}, updatedFieldDefinitions[index], { properties: {
50
+ label: updatedFieldDefinitions[index].properties.label,
51
+ href: updatedFieldDefinitions[index].properties.href,
52
+ cardinality: updatedFieldDefinitions[index].properties.cardinality,
53
+ values: response.data.value
54
+ } });
55
+ updatedFieldDefinitions.splice(index, 1, updatedReferenceIdentifier);
56
+ var newReceiverRequirements = __assign({}, receiverRequirements, { fieldDefinitions: updatedFieldDefinitions });
57
+ updateReceiverRequirementsProp(newReceiverRequirements);
58
+ })
59
+ .catch(function (error) {
60
+ setLoadingCostCenterValues(false);
61
+ // tslint:disable-next-line:no-console
62
+ console.log(error);
63
+ });
64
+ }
65
+ };
66
+ var getCostCenterInput = function (receiverRequirements, rapiBaseUrl, setLoadingCostCenterValues, loadingCostCenterValues, updateReceiverRequirementsProp) {
67
+ var costCenterFieldDefinition = getCostCenterFieldDefinitions(receiverRequirements);
68
+ if (costCenterFieldDefinition) {
69
+ if (costCenterFieldDefinition.properties && costCenterFieldDefinition.properties.hasOwnProperty("values") && costCenterFieldDefinition.properties.values) {
70
+ var selectProps = costCenterFieldDefinition.properties.hasOwnProperty("href")
71
+ ? {
72
+ showSearch: true,
73
+ filterOption: false,
74
+ onSearch: function (searchValue) {
75
+ handleReferenceIdentifierValueSearch(searchValue, costCenterFieldDefinition, receiverRequirements, rapiBaseUrl, setLoadingCostCenterValues, updateReceiverRequirementsProp);
76
+ },
77
+ onChange: function (searchValue) {
78
+ if (!searchValue) {
79
+ handleReferenceIdentifierValueSearch("", costCenterFieldDefinition, receiverRequirements, rapiBaseUrl, setLoadingCostCenterValues, updateReceiverRequirementsProp);
80
+ }
81
+ },
82
+ loading: loadingCostCenterValues,
83
+ }
84
+ : {};
85
+ return react_1.default.createElement(antd_1.Select, __assign({ dropdownMatchSelectWidth: false, allowClear: true }, selectProps), costCenterFieldDefinition.properties.values.map(function (costCenterFieldValue) {
86
+ return react_1.default.createElement(antd_1.Select.Option, { key: costCenterFieldValue.key, value: costCenterFieldValue.key }, costCenterFieldValue.name);
87
+ }));
88
+ }
89
+ else {
90
+ return react_1.default.createElement(antd_1.Input, null);
91
+ }
92
+ }
93
+ else {
94
+ return react_1.default.createElement(antd_1.Input, null);
95
+ }
96
+ };
97
+ var CostCenter = function (props) {
98
+ var receiverRequirements = props.receiverRequirements, rapiBaseUrl = props.rapiBaseUrl, updateReceiverRequirementsProp = props.updateReceiverRequirementsProp;
99
+ var _a = react_1.useState(false), loadingCostCenterValues = _a[0], setLoadingCostCenterValues = _a[1];
100
+ if (getCostCenterFieldDefinitions(receiverRequirements)) {
101
+ return (react_1.default.createElement(form_item_1.default, { receiverRequirements: receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.locationIdentifier"], defaultLabel: props.intl.formatMessage(translationMessages.baseInformation_costCenter), defaultIsRequired: false, fieldName: ["invoice", "customer", "locationIdentifier"] }, getCostCenterInput(receiverRequirements, rapiBaseUrl, setLoadingCostCenterValues, loadingCostCenterValues, updateReceiverRequirementsProp)));
102
+ }
103
+ else {
104
+ return null;
105
+ }
106
+ };
107
+ exports.default = react_intl_1.injectIntl(CostCenter);
@@ -22,6 +22,7 @@ var icons_1 = require("@ant-design/icons");
22
22
  var RequirementsUtility_1 = require("../../../utils/RequirementsUtility");
23
23
  var OrderReference_1 = __importDefault(require("./OrderReference"));
24
24
  var AccountingCost_1 = __importDefault(require("./AccountingCost"));
25
+ var react_1 = require("react");
25
26
  var translationMessages = react_intl_1.defineMessages({
26
27
  baseInformation_title: {
27
28
  id: "baseInformation_title",
@@ -55,6 +56,10 @@ var translationMessages = react_intl_1.defineMessages({
55
56
  id: "baseInformation_buyerReferenceLabel_helpText",
56
57
  defaultMessage: "A reference the buyer has requested to be assigned to the invoice, often called \"your reference\". Used by the buyer for internal routing. If buyer has not specifically requested it, the name of the person who ordered or requested the products or services can be used. Must be used when order number is not specified."
57
58
  },
59
+ baseInformation_projectReferenceLabel: {
60
+ id: "baseInformation_projectReferenceLabel",
61
+ defaultMessage: "Project reference"
62
+ },
58
63
  baseInformation_notes: {
59
64
  id: "baseInformation_notes",
60
65
  defaultMessage: "Notes"
@@ -97,6 +102,11 @@ var translationMessages = react_intl_1.defineMessages({
97
102
  },
98
103
  });
99
104
  var BaseInformation = function (props) {
105
+ var _a = react_1.useState(), dueDateDefaultPickerValue = _a[0], setDueDateDefaultPickerValue = _a[1];
106
+ react_1.useEffect(function () {
107
+ var a = getDueDateLimit(props.form.getFieldValue(["invoice", "issueDate"]), props.dueDateMinimumOffset);
108
+ setDueDateDefaultPickerValue(a);
109
+ }, [props.form.getFieldValue(["invoice", "issueDate"])]);
100
110
  var getCurrencies = function (recRequirements) {
101
111
  var currencies = [
102
112
  {
@@ -136,14 +146,7 @@ var BaseInformation = function (props) {
136
146
  return currencies;
137
147
  }
138
148
  };
139
- var disabledDate = function (dueDate, issueDate, dueDateMinimumOffset) {
140
- // const baseDate = issueDate
141
- // ? issueDate.startOf("day") > moment().startOf("day")
142
- // ? issueDate.clone().startOf("day")
143
- // : moment().startOf("day")
144
- // : moment().startOf("day");
145
- // // const baseDate = moment().startOf("day");
146
- // const addedDate = dueDateMinimumOffset ? baseDate.add(dueDateMinimumOffset, "days") : baseDate;
149
+ var getDueDateLimit = function (issueDate, dueDateMinimumOffset) {
147
150
  var dueDateLimit;
148
151
  if (issueDate) {
149
152
  dueDateLimit = moment_1.default.max(moment_1.default().startOf("day").add(dueDateMinimumOffset, "days"), issueDate.startOf("day"));
@@ -151,6 +154,10 @@ var BaseInformation = function (props) {
151
154
  else {
152
155
  dueDateLimit = moment_1.default().startOf("day").add(dueDateMinimumOffset, "days");
153
156
  }
157
+ return dueDateLimit;
158
+ };
159
+ var disabledDate = function (dueDate, issueDate, dueDateMinimumOffset) {
160
+ var dueDateLimit = getDueDateLimit(issueDate, dueDateMinimumOffset);
154
161
  return dueDate < dueDateLimit;
155
162
  };
156
163
  var checkIfEmpty = function (date) {
@@ -185,7 +192,11 @@ var BaseInformation = function (props) {
185
192
  React.createElement(antd_1.Input, null)),
186
193
  React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.issueDate, defaultLabel: issueDateLabelNode, defaultIsRequired: true, fieldName: ["invoice", "issueDate"] },
187
194
  React.createElement(antd_1.DatePicker, { style: { width: "100%" }, format: "DD.MM.YYYY" })),
188
- React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.dueDate, defaultLabel: dueDateLabelNode, defaultIsRequired: true, fieldName: ["invoice", "dueDate"], additionalRules: [
195
+ React.createElement(form_item_1.default
196
+ // dependencies={[["invoice", "issueDate"]]}
197
+ , {
198
+ // dependencies={[["invoice", "issueDate"]]}
199
+ receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields.dueDate, defaultLabel: dueDateLabelNode, defaultIsRequired: true, fieldName: ["invoice", "dueDate"], additionalRules: [
189
200
  {
190
201
  validator: (function (rule, value, callback) {
191
202
  if (!value) {
@@ -198,10 +209,10 @@ var BaseInformation = function (props) {
198
209
  }),
199
210
  },
200
211
  ] },
201
- React.createElement(antd_1.DatePicker, { style: { width: "100%" }, format: "DD.MM.YYYY", onChange: checkIfEmpty, disabledDate: (function (current) {
212
+ React.createElement(antd_1.DatePicker, { defaultPickerValue: dueDateDefaultPickerValue, style: { width: "100%" }, format: "DD.MM.YYYY", onChange: checkIfEmpty, getPopupContainer: function (trigger) { return trigger.parentElement; }, disabledDate: (function (current) {
202
213
  var currentDate = current;
203
- var issueDate = props.form.getFieldValue(["invoice", "issueDate"]);
204
214
  var dueDateMinimumOffset = props.dueDateMinimumOffset;
215
+ var issueDate = props.form.getFieldValue(["invoice", "issueDate"]);
205
216
  return disabledDate(currentDate, issueDate, dueDateMinimumOffset);
206
217
  }) })),
207
218
  React.createElement(OrderReference_1.default, { receiverRequirements: props.receiverRequirements, formInstance: props.form, dependencies: [["invoice", "buyerReference"]] }),
@@ -209,6 +220,8 @@ var BaseInformation = function (props) {
209
220
  React.createElement(antd_1.Input, null)),
210
221
  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 }),
211
222
  React.createElement(AccountingCost_1.default, { formInstance: props.form, rapiBaseUrl: props.rapiBaseUrl, receiverRequirements: props.receiverRequirements, updateReceiverRequirementsProp: props.updateReceiverRequirementsProp, legalIdentifier: props.legalIdentifier }),
223
+ React.createElement(form_item_1.default, { receiverRequirements: props.receiverRequirements, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["documentReferences.project.documentNo"], defaultLabel: props.intl.formatMessage(translationMessages.baseInformation_projectReferenceLabel), defaultIsRequired: false, fieldName: ["invoice", "documentReferences", "project", "documentNo"] },
224
+ React.createElement(antd_1.Input, null)),
212
225
  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"] },
213
226
  React.createElement(antd_1.Input.TextArea, null)),
214
227
  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 },
@@ -18,6 +18,7 @@ export declare enum AvailableFields {
18
18
  "notes" = "notes",
19
19
  "accountingCost" = "accountingCost",
20
20
  "buyerReference" = "buyerReference",
21
+ "documentReferences.project.documentNo" = "documentReferences.project.documentNo",
21
22
  "orderReference.documentNo" = "orderReference.documentNo",
22
23
  "billingReferences.invoices" = "billingReferences.invoices",
23
24
  "billingReferences.documentNo" = "billingReferences.documentNo",
@@ -10,6 +10,7 @@ var AvailableFields;
10
10
  AvailableFields["notes"] = "notes";
11
11
  AvailableFields["accountingCost"] = "accountingCost";
12
12
  AvailableFields["buyerReference"] = "buyerReference";
13
+ AvailableFields["documentReferences.project.documentNo"] = "documentReferences.project.documentNo";
13
14
  AvailableFields["orderReference.documentNo"] = "orderReference.documentNo";
14
15
  AvailableFields["billingReferences.invoices"] = "billingReferences.invoices";
15
16
  AvailableFields["billingReferences.documentNo"] = "billingReferences.documentNo";
@@ -0,0 +1,11 @@
1
+ import { ProfileOutputWithApiKey } from "../common/types/AppConfiguration";
2
+ import React from "react";
3
+ import { InjectedIntlProps } from "react-intl";
4
+ import { CommonProps } from "../common/types/CommonProps";
5
+ interface Props extends CommonProps, InjectedIntlProps {
6
+ customers: ProfileOutputWithApiKey[];
7
+ }
8
+ declare const _default: React.ComponentClass<Pick<Props, "customers" | "language" | "mapiBaseUrl" | "rapiBaseUrl">, any> & {
9
+ WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
10
+ };
11
+ export default _default;
@@ -0,0 +1,213 @@
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 __importStar = (this && this.__importStar) || function (mod) {
14
+ if (mod && mod.__esModule) return mod;
15
+ var result = {};
16
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
17
+ result["default"] = mod;
18
+ return result;
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var mapi_1 = require("@unimaze/api-clients/lib/mapi");
22
+ var models_1 = require("@unimaze/api-clients/lib/mapi/models");
23
+ var antd_1 = require("antd");
24
+ var formLayout_1 = require("../common/consts/formLayout");
25
+ var components_1 = require("../common/components");
26
+ var react_1 = __importStar(require("react"));
27
+ var react_intl_1 = require("react-intl");
28
+ var utils_1 = require("../utils");
29
+ var BillingLineUtility_1 = require("../utils/BillingLineUtility");
30
+ var paymentMethodForConversion_1 = require("../common/components/payment-method/paymentMethodForConversion");
31
+ var uuid_1 = require("uuid");
32
+ var translationMessages = react_intl_1.defineMessages({
33
+ createInvoice_addDocumentLineMsg: {
34
+ id: "createInvoice_addDocumentLineMsg",
35
+ defaultMessage: "Add at least one document line",
36
+ },
37
+ createInvoice_selectCustomerMsg: {
38
+ id: "createInvoice_selectCustomerMsg",
39
+ defaultMessage: "Customer must be selected",
40
+ },
41
+ createInvoice_successfullySubmittedInvoiceMsg: {
42
+ id: "createInvoice_successfullySubmittedInvoiceMsg",
43
+ defaultMessage: "Successfully submitted the invoice"
44
+ },
45
+ createInvoice_successfullyUploadedAttachmentMsg: {
46
+ id: "createInvoice_successfullyUploadedAttachmentMsg",
47
+ defaultMessage: "Successfully uploaded attachment {attachment}"
48
+ },
49
+ createInvoice_ErrorUploadedAttachmentMsg: {
50
+ id: "createInvoice_ErrorUploadedAttachmentMsg",
51
+ defaultMessage: "Error uploaded attachment {attachment}"
52
+ },
53
+ createInvoice_Submit: {
54
+ id: "createInvoice_Submit",
55
+ defaultMessage: "Submit"
56
+ },
57
+ });
58
+ var CreateInvoiceConstructor = function (props) {
59
+ // const [submitInvoiceRequest, setSubmitInvoiceRequest] = React.useState<CreateSubmitInvoiceRequest>();
60
+ var intl = props.intl;
61
+ var form = antd_1.Form.useForm()[0];
62
+ var _a = react_1.useState(false), submitting = _a[0], setSubmitting = _a[1];
63
+ var _b = react_1.useState(/*profileOutputToPartyMetadata(customers[0])*/ undefined), chosenCustomer = _b[0], setChosenCustomer = _b[1];
64
+ var _c = react_1.useState(), chosenCustomerApiKey = _c[0], setChosenCustomerApiKey = _c[1];
65
+ var _d = react_1.useState(1), billingLinesEditableIndex = _d[0], setBillingLinesEditableIndex = _d[1];
66
+ var initialBillingLineData = {
67
+ key: billingLinesEditableIndex,
68
+ itemNo: "Item No.",
69
+ quantity: 0,
70
+ taxAmount: 0,
71
+ name: "New Item",
72
+ unitOfMeasure: { value: models_1.UnitOfMeasureMetadataUnitEnum.Piece, label: "Piece" },
73
+ unitPriceAmount: 0,
74
+ taxCategoryType: { value: models_1.BillingLineMetadataTaxCategoryTypeEnum.Exempt, label: "Exempt (0%)" },
75
+ discountValue: "0",
76
+ taxableAmount: 0,
77
+ taxPercentage: null
78
+ };
79
+ var _e = react_1.useState([__assign({}, initialBillingLineData, { key: 0 })]), billingLinesDataSource = _e[0], setBillingLinesDataSource = _e[1];
80
+ // BILLING LINES
81
+ var handleBillingLinesDelete = function (index) {
82
+ var newDataSource = billingLinesDataSource.slice();
83
+ var indexToDelete = newDataSource.findIndex(function (billingLine) { return billingLine.key === index; });
84
+ newDataSource.splice(indexToDelete, 1);
85
+ setBillingLinesDataSource(newDataSource);
86
+ };
87
+ var handleBillingLinesAdd = function (billingLineToAdd) {
88
+ setBillingLinesDataSource(billingLinesDataSource.concat([billingLineToAdd]));
89
+ setBillingLinesEditableIndex(billingLinesEditableIndex + 1);
90
+ };
91
+ var handleBillingLinesSave = function (row, formInstance) {
92
+ var newData = billingLinesDataSource.slice();
93
+ var index = newData.findIndex(function (i) {
94
+ return row.key === i.key;
95
+ });
96
+ var item = newData[index];
97
+ newData.splice(index, 1, __assign({}, item, row));
98
+ var billingLineMetadata = newData.map(function (current) {
99
+ return __assign({}, current, { unitOfMeasure: {
100
+ unit: models_1.UnitOfMeasureMetadataUnitEnum[current.unitOfMeasure.value],
101
+ }, taxCategoryType: models_1.BillingLineMetadataTaxCategoryTypeEnum[current.taxCategoryType.value] });
102
+ });
103
+ setBillingLinesDataSource(newData);
104
+ handleSetBillingLineMetadata(formInstance, billingLineMetadata);
105
+ };
106
+ // END BILLING LINES
107
+ var handleSetBillingLineMetadata = function (formInstance, billingLineMetadata) {
108
+ formInstance.setFieldsValue({
109
+ "billingLinesMetadata": billingLineMetadata
110
+ });
111
+ };
112
+ var handleSubmit = function (values) {
113
+ setSubmitting(true);
114
+ var attachments = [
115
+ values.attachments.file1 && values.attachments.file1,
116
+ values.attachments.file2 && values.attachments.file2,
117
+ values.attachments.file3 && values.attachments.file3,
118
+ ];
119
+ // Clear the array of undefined
120
+ attachments = attachments.filter(function (attachment) { return attachment.file !== undefined; });
121
+ var billingLinesArray = form.getFieldValue("billingLinesMetadata");
122
+ if (!billingLinesArray || billingLinesArray.length <= 0) {
123
+ antd_1.message.error(intl.formatMessage(translationMessages.createInvoice_addDocumentLineMsg));
124
+ return;
125
+ }
126
+ if (!chosenCustomer) {
127
+ antd_1.message.error(intl.formatMessage(translationMessages.createInvoice_selectCustomerMsg));
128
+ return;
129
+ }
130
+ var invoiceMetadataInput = utils_1.convertToInvoiceMetadataInput(values, BillingLineUtility_1.billingLinesFieldsMetadata(form), paymentMethodForConversion_1.PaymentMethodFormData(values), chosenCustomer);
131
+ var createSubmitInvoice = {
132
+ invoiceMetadataInput: invoiceMetadataInput,
133
+ more: attachments.length > 0,
134
+ messageId: uuid_1.v4(),
135
+ processingMode: mapi_1.TransactionProcessingMode.Device
136
+ // processingMode: TransactionProcessingMode.DeviceRouted
137
+ };
138
+ utils_1.submitInvoice(createSubmitInvoice, props.mapiBaseUrl, chosenCustomerApiKey, "submitInvoice", props.language)
139
+ .then(function (resp) {
140
+ antd_1.message.success(intl.formatMessage(translationMessages.createInvoice_successfullySubmittedInvoiceMsg));
141
+ var messageId = resp.data.uniqueId;
142
+ var _loop_1 = function () {
143
+ var nextFileArray = attachments.splice(0, 1);
144
+ var nextFile = nextFileArray[0].file[0].originFileObj;
145
+ var nextFileDescription = nextFileArray[0].description;
146
+ var createAttachDocument = {
147
+ messageId: messageId,
148
+ contentType: nextFile.type,
149
+ more: attachments.length > 0,
150
+ name: nextFileDescription // nextFile.name,
151
+ };
152
+ setSubmitting(true);
153
+ utils_1.submitDocument(nextFile, createAttachDocument, props.mapiBaseUrl, chosenCustomerApiKey)
154
+ .then(function (submitDocumentResponse) {
155
+ antd_1.message.success(intl.formatMessage(translationMessages.createInvoice_successfullyUploadedAttachmentMsg, { attachment: nextFileDescription }));
156
+ setSubmitting(false);
157
+ })
158
+ .catch(function (documentSendingErrorMessage) {
159
+ antd_1.message.error(intl.formatMessage(translationMessages.createInvoice_ErrorUploadedAttachmentMsg, { attachment: nextFileDescription }) + " - " + documentSendingErrorMessage.message);
160
+ setSubmitting(false);
161
+ });
162
+ };
163
+ while (attachments.length > 0) {
164
+ _loop_1();
165
+ }
166
+ setSubmitting(false);
167
+ form.resetFields();
168
+ // Clear the billing line dataSource
169
+ setChosenCustomer(undefined);
170
+ setChosenCustomerApiKey(undefined);
171
+ setBillingLinesDataSource([__assign({}, initialBillingLineData, { key: 0 })]);
172
+ setBillingLinesEditableIndex(0);
173
+ location.reload();
174
+ })
175
+ .catch(function (error) {
176
+ setSubmitting(false);
177
+ antd_1.message.error(error.message);
178
+ });
179
+ };
180
+ return (react_1.default.createElement(antd_1.Spin, { spinning: submitting },
181
+ react_1.default.createElement(antd_1.Form, __assign({}, formLayout_1.formItemLayout, { form: form, onFinish: handleSubmit, initialValues: {
182
+ invoice: {
183
+ currencyCode: "ISK",
184
+ supplier: {
185
+ address: {
186
+ countryCode: "IS"
187
+ }
188
+ },
189
+ customer: {
190
+ address: {
191
+ countryCode: "IS"
192
+ }
193
+ }
194
+ }
195
+ } }),
196
+ react_1.default.createElement(antd_1.Row, { gutter: [16, 16] },
197
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
198
+ react_1.default.createElement(components_1.BaseInformation, { form: form, documentType: "invoice" })),
199
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
200
+ react_1.default.createElement(components_1.Supplier, { billingLinesDataSource: billingLinesDataSource })),
201
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
202
+ react_1.default.createElement(components_1.Customer, { formInstance: form, customers: props.customers, chosenCustomer: chosenCustomer, setChosenCustomer: setChosenCustomer, setChosenCustomerApiKey: setChosenCustomerApiKey })),
203
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 24 } },
204
+ react_1.default.createElement(components_1.BillingLines, { setBillingLineMetadata: handleSetBillingLineMetadata, formInstance: form, dataSource: billingLinesDataSource, editableIndex: billingLinesEditableIndex, handleAdd: handleBillingLinesAdd, initialBillingLineData: initialBillingLineData, handleDelete: handleBillingLinesDelete, handleSave: handleBillingLinesSave })),
205
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
206
+ react_1.default.createElement(components_1.PaymentMethod, null)),
207
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 16 } },
208
+ react_1.default.createElement(components_1.Attachments /*handleAddFile={handleAddFile}*/, null)),
209
+ react_1.default.createElement(antd_1.Row, { style: { width: "100%", padding: "8px" }, justify: "end" },
210
+ react_1.default.createElement(antd_1.Col, null,
211
+ react_1.default.createElement(antd_1.Button, { type: "primary", htmlType: "submit", size: "large" }, intl.formatMessage(translationMessages.createInvoice_Submit))))))));
212
+ };
213
+ exports.default = react_intl_1.injectIntl(CreateInvoiceConstructor);
@@ -31,9 +31,9 @@ var utils_1 = require("../utils");
31
31
  var BillingLineUtility_1 = require("../utils/BillingLineUtility");
32
32
  var paymentMethodForConversion_1 = require("../common/components/payment-method/paymentMethodForConversion");
33
33
  var uuid_1 = require("uuid");
34
- var react_google_recaptcha_1 = __importDefault(require("react-google-recaptcha"));
35
34
  var ApiUtility_1 = require("../utils/ApiUtility");
36
35
  var ConversionUtility_1 = require("../utils/ConversionUtility");
36
+ var reaptcha_1 = __importDefault(require("reaptcha"));
37
37
  var translationMessages = react_intl_1.defineMessages({
38
38
  createInvoice_addDocumentLineMsg: {
39
39
  id: "createInvoice_addDocumentLineMsg",
@@ -59,6 +59,18 @@ var translationMessages = react_intl_1.defineMessages({
59
59
  id: "createInvoice_Submit",
60
60
  defaultMessage: "Submit"
61
61
  },
62
+ createInvoice_SendCopy: {
63
+ id: "createInvoice_SendCopy",
64
+ defaultMessage: "Send a copy"
65
+ },
66
+ createInvoice_SendCopyTooltip: {
67
+ id: "createInvoice_SendCopyTooltip",
68
+ defaultMessage: "Sends you a PDF copy of the invoice"
69
+ },
70
+ createInvoice_SendCopyTooltipDisabled: {
71
+ id: "createInvoice_SendCopyTooltipDisabled",
72
+ defaultMessage: "You must fill in your email address to send yourself a copy"
73
+ },
62
74
  });
63
75
  /**
64
76
  * Component for creating a form for creating an invoice and submitting it to the MAPI transaction services
@@ -78,14 +90,18 @@ var CreateInvoiceConstructor = function (props) {
78
90
  var _g = react_1.default.useState(""), referenceIdentifierValidateStatus = _g[0], setReferenceIdentifierValidateStatus = _g[1];
79
91
  // const [billingLinesEditableIndex, setBillingLinesEditableIndex] = useState<number>(1)
80
92
  var _h = react_1.useState(false), outsideVatScope = _h[0], setOutsideVatScope = _h[1];
93
+ var _j = react_1.useState(false), captchaVerified = _j[0], setCaptchaVerified = _j[1];
94
+ react_1.useEffect(function () {
95
+ setIsSubmitDisabled(!captchaVerified);
96
+ }, [captchaVerified]);
81
97
  // attachments
82
98
  // TODO: remove the states, set the values to the form in attachment components
83
- var _j = react_1.useState([]), file1 = _j[0], setFile1 = _j[1];
84
- var _k = react_1.useState(""), attachmentFieldValidation1 = _k[0], setAttachmentFieldValidation1 = _k[1];
85
- var _l = react_1.useState([]), file2 = _l[0], setFile2 = _l[1];
86
- var _m = react_1.useState(""), attachmentFieldValidation2 = _m[0], setAttachmentFieldValidation2 = _m[1];
87
- var _o = react_1.useState([]), file3 = _o[0], setFile3 = _o[1];
88
- var _p = react_1.useState(""), attachmentFieldValidation3 = _p[0], setAttachmentFieldValidation3 = _p[1];
99
+ var _k = react_1.useState([]), file1 = _k[0], setFile1 = _k[1];
100
+ var _l = react_1.useState(""), attachmentFieldValidation1 = _l[0], setAttachmentFieldValidation1 = _l[1];
101
+ var _m = react_1.useState([]), file2 = _m[0], setFile2 = _m[1];
102
+ var _o = react_1.useState(""), attachmentFieldValidation2 = _o[0], setAttachmentFieldValidation2 = _o[1];
103
+ var _p = react_1.useState([]), file3 = _p[0], setFile3 = _p[1];
104
+ var _q = react_1.useState(""), attachmentFieldValidation3 = _q[0], setAttachmentFieldValidation3 = _q[1];
89
105
  react_1.useEffect(function () {
90
106
  form.resetFields([
91
107
  ["invoice", "supplier", "vatNumber"],
@@ -121,8 +137,14 @@ var CreateInvoiceConstructor = function (props) {
121
137
  react_1.useEffect(function () {
122
138
  if (supplierEmailValue) {
123
139
  form.validateFields([["invoice", "supplier", "contact", "electronicMail"]])
124
- .then(function (v) { return setSendCopyDisabled(!supplierEmailValue); })
125
- .catch(function (e) { return setSendCopyDisabled(true); });
140
+ .then(function (v) {
141
+ setSendCopyDisabled(!supplierEmailValue);
142
+ setSendCopy(true);
143
+ })
144
+ .catch(function (e) {
145
+ setSendCopyDisabled(true);
146
+ setSendCopy(false);
147
+ });
126
148
  }
127
149
  else {
128
150
  setSendCopy(false);
@@ -291,7 +313,7 @@ var CreateInvoiceConstructor = function (props) {
291
313
  });
292
314
  setChosenCustomerApiKey(props.customers[0].apiKey);
293
315
  }
294
- var _q = react_1.useState(undefined), billingLinesMetadata = _q[0], setBillingLinesMetadata = _q[1];
316
+ var _r = react_1.useState(undefined), billingLinesMetadata = _r[0], setBillingLinesMetadata = _r[1];
295
317
  var getBillingLines = function (changedValues, allValues) {
296
318
  var invoiceLines = allValues.invoice.invoiceLines;
297
319
  if (invoiceLines) {
@@ -317,7 +339,14 @@ var CreateInvoiceConstructor = function (props) {
317
339
  }
318
340
  };
319
341
  return (react_1.default.createElement(antd_1.Spin, { spinning: submitting },
320
- react_1.default.createElement(antd_1.Form, __assign({ scrollToFirstError: true, onValuesChange: function (changedValues, allValues) { return getBillingLines(changedValues, allValues); } }, formLayout_1.formItemLayout, { form: form, onFinish: handleSubmit, initialValues: {
342
+ react_1.default.createElement(antd_1.Form, __assign({ onFieldsChange: function () {
343
+ if (captchaVerified && recaptchaRef) {
344
+ if (recaptchaRef.current) {
345
+ setCaptchaVerified(false);
346
+ recaptchaRef.current.reset();
347
+ }
348
+ }
349
+ }, scrollToFirstError: true, onValuesChange: function (changedValues, allValues) { return getBillingLines(changedValues, allValues); } }, formLayout_1.formItemLayout, { form: form, onFinish: handleSubmit, initialValues: {
321
350
  invoice: {
322
351
  supplier: {
323
352
  address: {
@@ -368,12 +397,13 @@ var CreateInvoiceConstructor = function (props) {
368
397
  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 })),
369
398
  react_1.default.createElement(antd_1.Row, { style: { width: "100%", padding: "8px" }, justify: "end" },
370
399
  react_1.default.createElement(antd_1.Col, null,
371
- react_1.default.createElement(react_google_recaptcha_1.default, { ref: recaptchaRef, sitekey: "6LdMUdEZAAAAAG--2WEyu8CIRVlv6CzdZIwaQ-zt", onChange: function (token) {
372
- setIsSubmitDisabled(!token);
373
- }, hl: props.language }))),
400
+ react_1.default.createElement(reaptcha_1.default, { sitekey: "6LdMUdEZAAAAAG--2WEyu8CIRVlv6CzdZIwaQ-zt", ref: recaptchaRef, onVerify: function (response) {
401
+ setCaptchaVerified(true);
402
+ }, hl: props.language, onExpire: function () { return setCaptchaVerified(false); }, onError: function () { return setCaptchaVerified(false); } }))),
374
403
  react_1.default.createElement(antd_1.Row, { style: { width: "100%", padding: "8px" }, justify: "end" },
375
404
  react_1.default.createElement(antd_1.Col, null,
376
- react_1.default.createElement(antd_1.Checkbox, { disabled: sendCopyDisabled, checked: sendCopy, onChange: function (e) { return setSendCopy(e.target.checked); } }, "Send a copy")),
405
+ react_1.default.createElement(antd_1.Tooltip, { title: sendCopyDisabled ? intl.formatMessage(translationMessages.createInvoice_SendCopyTooltipDisabled) : intl.formatMessage(translationMessages.createInvoice_SendCopyTooltip) },
406
+ react_1.default.createElement(antd_1.Checkbox, { disabled: sendCopyDisabled, checked: sendCopy, onChange: function (e) { return setSendCopy(e.target.checked); } }, intl.formatMessage(translationMessages.createInvoice_SendCopy)))),
377
407
  react_1.default.createElement(antd_1.Col, null,
378
408
  react_1.default.createElement(antd_1.Button, { type: "primary", htmlType: "submit", size: "large", disabled: isSubmitDisabled }, intl.formatMessage(translationMessages.createInvoice_Submit))))))));
379
409
  };
@@ -0,0 +1 @@
1
+ import "antd/dist/antd.compact.css";
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { InjectedIntlProps } from "react-intl";
3
+ interface Props extends InjectedIntlProps {
4
+ fieldName: "file1" | "file2" | "file3";
5
+ }
6
+ interface States {
7
+ file: any[];
8
+ }
9
+ declare class Attachment extends React.Component<Props, States> {
10
+ constructor(props: Props);
11
+ handleRemoveFile: () => void;
12
+ normFile: (e: any) => any;
13
+ render(): JSX.Element;
14
+ }
15
+ declare const _default: React.ComponentClass<Pick<Props & React.RefAttributes<Attachment>, "ref" | "key" | "fieldName">, any> & {
16
+ WrappedComponent: React.ComponentType<Props & React.RefAttributes<Attachment> & InjectedIntlProps>;
17
+ };
18
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import { InjectedIntlProps } from "react-intl";
3
+ declare const AttachmentGroupIntl: React.ComponentClass<Pick<InjectedIntlProps, never>, any> & {
4
+ WrappedComponent: React.ComponentType<InjectedIntlProps>;
5
+ };
6
+ export default AttachmentGroupIntl;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { InjectedIntlProps } from "react-intl";
3
+ import { StoreValue } from "rc-field-form/lib/interface";
4
+ interface FieldData {
5
+ name: number;
6
+ key: number;
7
+ fieldKey: number;
8
+ }
9
+ interface Props extends InjectedIntlProps {
10
+ fields: FieldData[];
11
+ add: (defaultValue?: StoreValue) => void;
12
+ remove: (index: number) => void;
13
+ }
14
+ declare const _default: React.ComponentClass<Pick<Props, "remove" | "fields" | "add">, any> & {
15
+ WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
16
+ };
17
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { FormInstance } from "antd/es/form";
3
+ import { InjectedIntlProps } from "react-intl";
4
+ interface Props extends InjectedIntlProps {
5
+ form: FormInstance;
6
+ documentType: "creditNote" | "invoice";
7
+ }
8
+ declare const BaseInformationIntl: React.ComponentClass<Pick<Props, "form" | "documentType">, any> & {
9
+ WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
10
+ };
11
+ export default BaseInformationIntl;