@unimaze/billing 0.2.4 → 0.2.6

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.
@@ -35,7 +35,6 @@ var React = __importStar(require("react"));
35
35
  // import '@ant-design/compatible/assets/index.css';
36
36
  var antd_1 = require("antd");
37
37
  var react_intl_1 = require("react-intl");
38
- var icons_1 = require("@ant-design/icons");
39
38
  var formLayout_1 = require("../../consts/formLayout");
40
39
  var translationMessages = react_intl_1.defineMessages({
41
40
  attachment_labels_Reference: {
@@ -95,9 +94,7 @@ var Attachment = /** @class */ (function (_super) {
95
94
  // this.props.intl.formatMessage(translationMessages.attachment_labels_File)
96
95
  label: "Skrá", name: ["attachments", "" + fieldName, "file"], valuePropName: "fileList", getValueFromEvent: this.normFile }),
97
96
  React.createElement(antd_1.Upload.Dragger, { name: "attachment:" + fieldName, multiple: false, onRemove: this.handleRemoveFile, beforeUpload: function () { return false; } },
98
- React.createElement("p", { className: "ant-upload-drag-icon" },
99
- React.createElement(icons_1.InboxOutlined, null)),
100
- React.createElement("p", { style: { padding: "1em" } }, "Smelltu e\u00F0a drag\u00F0u inn skr\u00E1 h\u00E9r til a\u00F0 hla\u00F0a upp"))),
97
+ React.createElement("p", null, "Smelltu e\u00F0a drag\u00F0u inn skr\u00E1 h\u00E9r til a\u00F0 hla\u00F0a upp"))),
101
98
  React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemLayout, {
102
99
  // this.props.intl.formatMessage(translationMessages.attachment_labels_Description)
103
100
  label: "Lýsing", name: ["attachments", "" + fieldName, "description"], rules: [
@@ -26,11 +26,11 @@ var AttachmentsGroup = function (props) {
26
26
  // props.intl.formatMessage(translationMessages.attachment_title)}
27
27
  React.createElement(components_1.ComponentContainer, { title: "Viðhengi" },
28
28
  React.createElement(antd_1.Row, null,
29
- React.createElement(antd_1.Col, { span: 8 },
29
+ React.createElement(antd_1.Col, { span: 24 },
30
30
  React.createElement(Attachment_1.default, { key: "attachment1", fieldName: "file1" })),
31
- React.createElement(antd_1.Col, { span: 8 },
31
+ React.createElement(antd_1.Col, { span: 24 },
32
32
  React.createElement(Attachment_1.default, { key: "attachment2", fieldName: "file2" })),
33
- React.createElement(antd_1.Col, { span: 8 },
33
+ React.createElement(antd_1.Col, { span: 24 },
34
34
  React.createElement(Attachment_1.default, { key: "attachment3", fieldName: "file3" })))));
35
35
  };
36
36
  var AttachmentGroupIntl = react_intl_1.injectIntl(AttachmentsGroup);
@@ -8,11 +8,12 @@ interface Props extends InjectedIntlProps {
8
8
  setBillingLineMetadata: (formInstance: FormInstance, billingLineMetadata: BillingLineMetadata[]) => void;
9
9
  dataSource: BillingLineMetadataOverride[];
10
10
  handleDelete: (index: number) => void;
11
- handleAdd: () => void;
11
+ handleAdd: (billingLineToAdd: BillingLineMetadataOverride) => void;
12
12
  handleSave: (row: BillingLineMetadataOverride, formInstance: FormInstance) => void;
13
+ initialBillingLineData: BillingLineMetadataOverride;
13
14
  editableIndex: number;
14
15
  }
15
- declare const BillingLinesIntl: React.ComponentClass<Pick<Props, "dataSource" | "formInstance" | "setBillingLineMetadata" | "handleDelete" | "handleAdd" | "handleSave" | "editableIndex">, any> & {
16
+ declare const BillingLinesIntl: React.ComponentClass<Pick<Props, "dataSource" | "formInstance" | "setBillingLineMetadata" | "handleDelete" | "handleAdd" | "handleSave" | "initialBillingLineData" | "editableIndex">, any> & {
16
17
  WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
17
18
  };
18
19
  export default BillingLinesIntl;
@@ -44,6 +44,7 @@ var BillingLineUtility_1 = require("../../../utils/BillingLineUtility");
44
44
  var api_1 = require("@unimaze/api-clients/lib/mapi/api");
45
45
  var BillingCalculations_1 = __importDefault(require("./BillingCalculations"));
46
46
  var BillingTaxSummary_1 = __importDefault(require("./BillingTaxSummary"));
47
+ var formLayout_1 = require("../../consts/formLayout");
47
48
  var translationMessages = react_intl_1.defineMessages({
48
49
  billingLines_title: {
49
50
  id: "billingLines_title",
@@ -178,7 +179,7 @@ var BillingLines = /** @class */ (function (_super) {
178
179
  title: "",
179
180
  render: function (text, record, index) {
180
181
  return React.createElement(React.Fragment, null,
181
- React.createElement(icons_1.DeleteOutlined, { onClick: function () {
182
+ React.createElement(icons_1.MinusCircleOutlined, { onClick: function () {
182
183
  _this.props.handleDelete(index);
183
184
  } }));
184
185
  }
@@ -186,69 +187,6 @@ var BillingLines = /** @class */ (function (_super) {
186
187
  ];
187
188
  return _this;
188
189
  }
189
- // handleDelete = (index: number) => {
190
- // const newDataSource = [...this.state.dataSource];
191
- // newDataSource.splice(index, 1);
192
- //
193
- // this.setState((prevState: States) => ({
194
- // ...prevState,
195
- // dataSource: newDataSource,
196
- // }))
197
- // };
198
- //
199
- // handleAdd = () => {
200
- // const {dataSource} = this.state;
201
- // const newData: BillingLineMetadataOverride = {
202
- // key: this.state.editableIndex,
203
- // itemNo: "Item No.",// (dataSource.length > 0 ? Number(dataSource[dataSource.length-1].itemNo) + 1 : 1).toString(),
204
- // quantity: 0,
205
- // taxAmount: 0,
206
- // name: `New Item`,
207
- // unitOfMeasure: UnitOfMeasureMetadataUnitEnum.Piece,
208
- // unitPriceAmount: 0,
209
- // taxCategoryType: BillingLineMetadataTaxCategoryTypeEnum.StandardRated,
210
- // discountValue: "0",
211
- // taxableAmount: 0,
212
- // taxPercentage: null
213
- // };
214
- // this.setState(
215
- // {
216
- // ...this.state,
217
- // dataSource: [...dataSource, newData],
218
- // editableIndex: this.state.editableIndex + 1,
219
- // }
220
- // )
221
- // };
222
- //
223
- //
224
- // handleSave = (row: BillingLineMetadataOverride, formInstance: FormInstance) => {
225
- // const newData = [...this.state.dataSource];
226
- // const index = newData.findIndex((i) => {
227
- // return row.key === i.key;
228
- // });
229
- //
230
- // const item = newData[index];
231
- // newData.splice(index, 1, {
232
- // ...item,
233
- // ...row,
234
- // });
235
- //
236
- // const billingLineMetadata = newData.map<BillingLineMetadata>(current => {
237
- // return {
238
- // ...current,
239
- // unitOfMeasure: {
240
- // unit: current.unitOfMeasure,
241
- // }
242
- // }
243
- // });
244
- //
245
- // this.setState({
246
- // ...this.state,
247
- // dataSource: newData
248
- // });
249
- //
250
- // this.props.setBillingLineMetadata(formInstance, billingLineMetadata);
251
- // };
252
190
  BillingLines.prototype.render = function () {
253
191
  var _this = this;
254
192
  // const dataSource = this.props.formInstance.getFieldValue(["invoice", "invoiceLines"]);
@@ -276,8 +214,14 @@ var BillingLines = /** @class */ (function (_super) {
276
214
  // this.props.intl.formatMessage(translationMessages.billingLines_title)
277
215
  , {
278
216
  // this.props.intl.formatMessage(translationMessages.billingLines_title)
279
- title: "Reikningslínur", action: React.createElement(antd_1.Button, { onClick: this.props.handleAdd, type: "primary", style: { marginBottom: 16 } }, "Bæta við röð") },
280
- React.createElement(antd_1.Table, { style: { minHeight: "170px" }, components: components, dataSource: dataSource, columns: columns, pagination: false, rowKey: (function (record, index) { return index.toString(); }) }),
217
+ title: "Reikningslínur" },
218
+ React.createElement(antd_1.Table, {
219
+ // style={{minHeight: "170px"}}
220
+ components: components, dataSource: dataSource, columns: columns, pagination: false, rowKey: (function (record, index) { return index.toString(); }) }),
221
+ React.createElement(antd_1.Form.Item, __assign({}, formLayout_1.fullWidthInput),
222
+ React.createElement(antd_1.Button, { type: "dashed", onClick: function () { return _this.props.handleAdd(_this.props.initialBillingLineData); }, style: { width: "100%" } },
223
+ React.createElement(icons_1.PlusOutlined, null),
224
+ "Bæta við röð")),
281
225
  React.createElement(antd_1.Row, { style: { marginTop: "1em" }, align: "top", justify: "space-between", gutter: [16, 16] },
282
226
  React.createElement(antd_1.Col, { span: 16 },
283
227
  React.createElement(BillingTaxSummary_1.default, { billingLines: dataSource })),
@@ -1,6 +1,15 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { InjectedIntlProps } from "react-intl";
3
- declare const CustomerIntl: React.ComponentClass<Pick<InjectedIntlProps, never>, any> & {
4
- WrappedComponent: React.ComponentType<InjectedIntlProps>;
3
+ import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
4
+ import { FormInstance } from "antd/es/form";
5
+ import { PartyMetadata } from "@unimaze/api-clients/lib/mapi";
6
+ interface Props extends InjectedIntlProps {
7
+ customers: ProfileOutput[];
8
+ formInstance: FormInstance;
9
+ chosenCustomer: PartyMetadata | undefined;
10
+ setChosenCustomer: (chosenCustomer: PartyMetadata) => void;
11
+ }
12
+ declare const CustomerIntl: React.ComponentClass<Pick<Props, "formInstance" | "customers" | "chosenCustomer" | "setChosenCustomer">, any> & {
13
+ WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
5
14
  };
6
15
  export default CustomerIntl;
@@ -1,22 +1,27 @@
1
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;
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);
8
12
  };
9
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- var React = __importStar(require("react"));
17
+ var react_1 = __importDefault(require("react"));
14
18
  var components_1 = require("../../components");
15
19
  var antd_1 = require("antd");
16
20
  var ReceiverRequirements_1 = require("../../types/ReceiverRequirements");
17
21
  var form_item_1 = __importDefault(require("../form-item"));
18
- var RequirementsUtility_1 = require("../../../utils/RequirementsUtility");
19
22
  var react_intl_1 = require("react-intl");
23
+ var ConversionUtility_1 = require("../../../utils/ConversionUtility");
24
+ var formLayout_1 = require("../../consts/formLayout");
20
25
  var translationMessages = react_intl_1.defineMessages({
21
26
  customer_title: {
22
27
  id: "customer_title",
@@ -56,83 +61,33 @@ var translationMessages = react_intl_1.defineMessages({
56
61
  }
57
62
  });
58
63
  var Customer = function (props) {
64
+ var chosenCustomer = props.chosenCustomer, setChosenCustomer = props.setChosenCustomer;
65
+ var onCustomerChange = function (customerIndex) {
66
+ var customerPartyMetadata = ConversionUtility_1.profileOutputToPartyMetadata(props.customers[customerIndex]);
67
+ var prevValues = props.formInstance.getFieldsValue();
68
+ var newFormValues = __assign({}, prevValues, { invoice: __assign({}, prevValues.invoice, { customer: __assign({}, prevValues.invoice.customer, customerPartyMetadata) }) });
69
+ setChosenCustomer(__assign({}, prevValues.invoice.customer, customerPartyMetadata));
70
+ props.formInstance.setFieldsValue(newFormValues);
71
+ };
59
72
  return (
60
73
  // props.intl.formatMessage(translationMessages.customer_title)
61
- React.createElement(components_1.ComponentContainer, { title: "Viðskiptavinur" },
62
- React.createElement(form_item_1.default
63
- // receiverRequirements={receiverRequirementsObject}
64
- , {
65
- // receiverRequirements={receiverRequirementsObject}
66
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.name"],
67
- // props.intl.formatMessage(translationMessages.customer_name)
68
- defaultLabel: "Nafn viðskiptavinar", defaultIsRequired: true, fieldName: ["invoice", "customer", "name"], additionalRules: [
69
- {
70
- required: RequirementsUtility_1.getReceiverRequirements(ReceiverRequirements_1.receiverRequirementsObject, ReceiverRequirements_1.AvailableFields["customer.name"]).isRequired,
71
- message: 'Please input customer name',
72
- },
73
- ] },
74
- React.createElement(antd_1.Input, null)),
75
- React.createElement(form_item_1.default
76
- // receiverRequirements={receiverRequirementsObject}
77
- , {
78
- // receiverRequirements={receiverRequirementsObject}
79
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.identifier"],
80
- // props.intl.formatMessage(translationMessages.customer_identifier)
81
- defaultLabel: "Kennitala", defaultIsRequired: true, fieldName: ["invoice", "customer", "identifier"] },
82
- React.createElement(antd_1.Input, null)),
83
- React.createElement(form_item_1.default
84
- // receiverRequirements={receiverRequirementsObject}
85
- , {
86
- // receiverRequirements={receiverRequirementsObject}
87
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.address.streetNameAndNumber"],
88
- // props.intl.formatMessage(translationMessages.customer_address_streetNameAndNumber)
89
- defaultLabel: "Heimilisfang", defaultIsRequired: true, fieldName: ["invoice", "customer", "address", "streetNameAndNumber"] },
90
- React.createElement(antd_1.Input, null)),
91
- React.createElement(form_item_1.default
92
- // receiverRequirements={receiverRequirementsObject}
93
- , {
94
- // receiverRequirements={receiverRequirementsObject}
95
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.address.postalZone"],
96
- // props.intl.formatMessage(translationMessages.customer_address_zip_postalCode)
97
- defaultLabel: "Póstnúmer", defaultIsRequired: false, fieldName: ["invoice", "customer", "address", "postalZone"] },
98
- React.createElement(antd_1.Input, null)),
99
- React.createElement(form_item_1.default
100
- // receiverRequirements={receiverRequirementsObject}
101
- , {
102
- // receiverRequirements={receiverRequirementsObject}
103
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.address.city"],
104
- // props.intl.formatMessage(translationMessages.customer_address_city)
105
- defaultLabel: "Borg", defaultIsRequired: false, fieldName: ["invoice", "customer", "address", "city"] },
106
- React.createElement(antd_1.Input, null)),
107
- React.createElement(form_item_1.default
108
- // receiverRequirements={receiverRequirementsObject}
109
- , {
110
- // receiverRequirements={receiverRequirementsObject}
111
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.address.countryCode"],
112
- // props.intl.formatMessage(translationMessages.customer_address_countryCode)
113
- defaultLabel: "Landsnúmer", defaultIsRequired: true, fieldName: ["invoice", "customer", "address", "countryCode"] },
114
- React.createElement(antd_1.Input, { disabled: true })),
115
- React.createElement(form_item_1.default
116
- // receiverRequirements={receiverRequirementsObject}
117
- , {
118
- // receiverRequirements={receiverRequirementsObject}
119
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.contact.electronicMail"],
120
- // props.intl.formatMessage(translationMessages.customer_contact_email)
121
- defaultLabel: "Netfang", defaultIsRequired: false, fieldName: ["invoice", "customer", "contact", "electronicMail"], additionalRules: [
122
- {
123
- type: 'email',
124
- message: 'Þetta er ekki gilt netfang' // 'The input is not valid E-mail!',
125
- }
126
- ] },
127
- React.createElement(antd_1.Input, null)),
128
- React.createElement(form_item_1.default
129
- // receiverRequirements={receiverRequirementsObject}
130
- , {
131
- // receiverRequirements={receiverRequirementsObject}
132
- receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.contact.name"],
133
- // props.intl.formatMessage(translationMessages.customer_contact_name)
134
- defaultLabel: "Nafn tengiliðs", defaultIsRequired: false, fieldName: ["invoice", "customer", "contact", "name"] },
135
- React.createElement(antd_1.Input, null))));
74
+ react_1.default.createElement(components_1.ComponentContainer, { title: "Viðskiptavinur" },
75
+ react_1.default.createElement(form_item_1.default, { defaultLabel: "Select the customer", defaultIsRequired: true, receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["customer.identifier"], fieldName: ["invoice", "customer", "name"] },
76
+ react_1.default.createElement(antd_1.Select, { onChange: function (value) {
77
+ onCustomerChange(value);
78
+ } }, props.customers.map(function (customer, index) { return (react_1.default.createElement(antd_1.Select.Option, { key: index, value: index }, customer.name)); }))),
79
+ react_1.default.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemLayout, { label: "Nafn" }), chosenCustomer && chosenCustomer.name),
80
+ react_1.default.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemLayout, { label: "Kennitala" }), chosenCustomer && ConversionUtility_1.convertToReadableKennitala(chosenCustomer.identifier)),
81
+ react_1.default.createElement(antd_1.Form.Item, __assign({}, formLayout_1.formItemLayout, { label: "Heimilisfang" }), chosenCustomer && chosenCustomer.address
82
+ ? react_1.default.createElement(react_1.default.Fragment, null,
83
+ chosenCustomer.address.streetNameAndNumber,
84
+ react_1.default.createElement("br", null),
85
+ chosenCustomer.address.postalZone,
86
+ ", ",
87
+ chosenCustomer.address.city,
88
+ ", ",
89
+ chosenCustomer.address.countryCode)
90
+ : null)));
136
91
  };
137
92
  var CustomerIntl = react_intl_1.injectIntl(Customer);
138
93
  exports.default = CustomerIntl;
@@ -74,7 +74,7 @@ var EditableCell = function (props) {
74
74
  var editable = props.editable, dataIndex = props.dataIndex,
75
75
  // title,
76
76
  record = props.record, index = props.index, handleSave = props.handleSave, children = props.children, restProps = __rest(props, ["editable", "dataIndex", "record", "index", "handleSave", "children"]);
77
- var _a = react_1.useState(false), editing = _a[0], setEditing = _a[1];
77
+ var _a = react_1.useState(true), editing = _a[0], setEditing = _a[1];
78
78
  var input = null;
79
79
  var form = react_1.useContext(editable_row_1.EditableContext);
80
80
  var toggleEdit = function () {
@@ -136,6 +136,16 @@ var EditableCell = function (props) {
136
136
  var inputNode = getCorrectInputNode(dataIndex);
137
137
  var rules = validationRules_1.validationRules[dataIndex];
138
138
  return editing ? (react_1.default.createElement(antd_1.Form.Item, { style: { margin: 0 }, rules: rules, name: dataIndex, initialValue: record[dataIndex] }, inputNode)) : (react_1.default.createElement("div", { className: "editable-cell-value-wrap", style: { paddingRight: 24 }, onClick: toggleEdit }, children));
139
+ // return (
140
+ // <Form.Item
141
+ // style={{margin: 0}}
142
+ // rules={rules}
143
+ // name={dataIndex}
144
+ // initialValue={record[dataIndex]}
145
+ // >
146
+ // {inputNode}
147
+ // </Form.Item>
148
+ // )
139
149
  };
140
150
  return (react_1.default.createElement("td", __assign({}, restProps), editable ? (react_1.default.createElement(editable_row_1.EditableContext.Consumer, null, renderCell)) : (children)));
141
151
  };
@@ -74,7 +74,7 @@ var Supplier = function (props) {
74
74
  // receiverRequirements={receiverRequirementsObject}
75
75
  receiverRequirementsKey: ReceiverRequirements_1.AvailableFields["supplier.name"],
76
76
  // props.intl.formatMessage(translationMessages.supplier_name)
77
- defaultLabel: "Nafn birgja", defaultIsRequired: true, fieldName: ["invoice", "supplier", "name"] },
77
+ defaultLabel: "Nafn", defaultIsRequired: true, fieldName: ["invoice", "supplier", "name"] },
78
78
  React.createElement(antd_1.Input, null)),
79
79
  React.createElement(form_item_1.default
80
80
  // receiverRequirements={receiverRequirementsObject}
@@ -0,0 +1,14 @@
1
+ import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
2
+ interface AppConfiguration {
3
+ language: "en" | "is";
4
+ mapiUrl: string;
5
+ rapiUrl: string;
6
+ env: HostConfiguration[];
7
+ }
8
+ interface HostConfiguration {
9
+ host: string;
10
+ legalIdentifier: string;
11
+ apiKey: string;
12
+ customer: ProfileOutput[];
13
+ }
14
+ export { AppConfiguration, HostConfiguration };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
2
+ interface Configuration {
3
+ language: "en" | "is";
4
+ mapiUrl: string;
5
+ rapiUrl: string;
6
+ env: HostConfiguration[];
7
+ }
8
+ interface HostConfiguration {
9
+ host: string;
10
+ legalIdentifier: string;
11
+ apiKey: string;
12
+ customer: ProfileOutput[];
13
+ }
14
+ export { Configuration, HostConfiguration };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -183,7 +183,7 @@ exports.receiverRequirementsObject = {
183
183
  ]
184
184
  },
185
185
  "supplier.vatNumber": {
186
- isRequired: false,
186
+ isRequired: true,
187
187
  key: "",
188
188
  },
189
189
  "supplier.address.streetNameAndNumber": {
@@ -3,7 +3,7 @@ import React from "react";
3
3
  import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
4
4
  import { CommonProps } from "../common/types/CommonProps";
5
5
  interface Props extends CommonProps {
6
- customer: ProfileOutput;
6
+ customers: ProfileOutput[];
7
7
  }
8
8
  /**
9
9
  * Component for creating a form for creating an invoice and submitting it to the MAPI transaction services
@@ -42,39 +42,31 @@ var paymentMethodForConversion_1 = require("../common/components/payment-method/
42
42
  var CreateInvoice = function (props) {
43
43
  // const [submitInvoiceRequest, setSubmitInvoiceRequest] = React.useState<CreateSubmitInvoiceRequest>();
44
44
  var form = antd_1.Form.useForm()[0];
45
- var _a = react_1.useState([]), billingLinesDataSource = _a[0], setBillingLinesDataSource = _a[1];
46
- var _b = react_1.useState(0), billingLinesEditableIndex = _b[0], setBillingLinesEditableIndex = _b[1];
47
- // const [files, setFiles] = useState<UploadFile[]>([]);
48
- //
49
- // const handleAddFile = (file: UploadFile) => {
50
- // if (file.status === "removed") {
51
- // const remainingFiles = files.filter(existingFile => existingFile.uid !== file.uid);
52
- // setFiles(remainingFiles);
53
- // } else {
54
- // setFiles([...files, file])
55
- // }
56
- // };
45
+ var _a = react_1.useState(/*profileOutputToPartyMetadata(props.customers[0])*/ undefined), chosenCustomer = _a[0], setChosenCustomer = _a[1];
46
+ var _b = react_1.useState(1), billingLinesEditableIndex = _b[0], setBillingLinesEditableIndex = _b[1];
47
+ var initialBillingLineData = {
48
+ key: billingLinesEditableIndex,
49
+ itemNo: "Item No.",
50
+ quantity: 0,
51
+ taxAmount: 0,
52
+ name: "New Item",
53
+ unitOfMeasure: models_1.UnitOfMeasureMetadataUnitEnum.Piece,
54
+ unitPriceAmount: 0,
55
+ taxCategoryType: models_1.BillingLineMetadataTaxCategoryTypeEnum.Exempt,
56
+ discountValue: "0",
57
+ taxableAmount: 0,
58
+ taxPercentage: null
59
+ };
60
+ var _c = react_1.useState([__assign({}, initialBillingLineData, { key: 0 })]), billingLinesDataSource = _c[0], setBillingLinesDataSource = _c[1];
57
61
  // BILLING LINES
58
62
  var handleBillingLinesDelete = function (index) {
59
63
  var newDataSource = billingLinesDataSource.slice();
60
- newDataSource.splice(index, 1);
64
+ var indexToDelete = newDataSource.findIndex(function (billingLine) { return billingLine.key === index; });
65
+ newDataSource.splice(indexToDelete, 1);
61
66
  setBillingLinesDataSource(newDataSource);
62
67
  };
63
- var handleBillingLinesAdd = function () {
64
- var newData = {
65
- key: billingLinesEditableIndex,
66
- itemNo: "Item No.",
67
- quantity: 0,
68
- taxAmount: 0,
69
- name: "New Item",
70
- unitOfMeasure: models_1.UnitOfMeasureMetadataUnitEnum.Piece,
71
- unitPriceAmount: 0,
72
- taxCategoryType: models_1.BillingLineMetadataTaxCategoryTypeEnum.StandardRated,
73
- discountValue: "0",
74
- taxableAmount: 0,
75
- taxPercentage: null
76
- };
77
- setBillingLinesDataSource(billingLinesDataSource.concat([newData]));
68
+ var handleBillingLinesAdd = function (billingLineToAdd) {
69
+ setBillingLinesDataSource(billingLinesDataSource.concat([billingLineToAdd]));
78
70
  setBillingLinesEditableIndex(billingLinesEditableIndex + 1);
79
71
  };
80
72
  var handleBillingLinesSave = function (row, formInstance) {
@@ -111,12 +103,17 @@ var CreateInvoice = function (props) {
111
103
  antd_1.message.error("Add at least one document line");
112
104
  return;
113
105
  }
114
- var invoiceMetadataInput = utils_1.convertToInvoiceMetadataInput(values, BillingLineUtility_1.billingLinesFieldsMetadata(form), paymentMethodForConversion_1.PaymentMethodFormData(values), props.customer);
106
+ if (!chosenCustomer) {
107
+ antd_1.message.error("Customer must be selected");
108
+ return;
109
+ }
110
+ var invoiceMetadataInput = utils_1.convertToInvoiceMetadataInput(values, BillingLineUtility_1.billingLinesFieldsMetadata(form), paymentMethodForConversion_1.PaymentMethodFormData(values), chosenCustomer);
115
111
  var createSubmitInvoice = {
116
112
  invoiceMetadataInput: invoiceMetadataInput,
117
113
  more: attachments.length > 0,
118
114
  messageId: uuid_1.v4(),
119
- processingMode: mapi_1.TransactionProcessingMode.DeviceRouted
115
+ processingMode: mapi_1.TransactionProcessingMode.Device
116
+ // processingMode: TransactionProcessingMode.DeviceRouted
120
117
  };
121
118
  utils_1.submitInvoice(createSubmitInvoice, props.mapiBaseUrl, props.apiKey, "submitInvoice", props.language)
122
119
  .then(function (resp) {
@@ -142,7 +139,7 @@ var CreateInvoice = function (props) {
142
139
  }
143
140
  form.resetFields();
144
141
  // Clear the billing line dataSource
145
- setBillingLinesDataSource([]);
142
+ setBillingLinesDataSource([__assign({}, initialBillingLineData, { key: 0 })]);
146
143
  setBillingLinesEditableIndex(0);
147
144
  })
148
145
  .catch(function (error) {
@@ -179,16 +176,14 @@ var CreateInvoice = function (props) {
179
176
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 } },
180
177
  react_1.default.createElement(components_1.Supplier, { billingLinesDataSource: billingLinesDataSource })),
181
178
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 } },
182
- react_1.default.createElement(components_1.Customer, null)),
183
- react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 } },
184
- react_1.default.createElement(components_1.BaseInformation, { form: form, documentType: "invoice" })),
185
- react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 12 } },
186
- react_1.default.createElement(components_1.DeliveryLocation, null)),
179
+ react_1.default.createElement(components_1.Customer, { formInstance: form, customers: props.customers, chosenCustomer: chosenCustomer, setChosenCustomer: setChosenCustomer })),
187
180
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 24 } },
188
- react_1.default.createElement(components_1.BillingLines, { setBillingLineMetadata: handleSetBillingLineMetadata, formInstance: form, dataSource: billingLinesDataSource, editableIndex: billingLinesEditableIndex, handleAdd: handleBillingLinesAdd, handleDelete: handleBillingLinesDelete, handleSave: handleBillingLinesSave })),
181
+ react_1.default.createElement(components_1.BillingLines, { setBillingLineMetadata: handleSetBillingLineMetadata, formInstance: form, dataSource: billingLinesDataSource, editableIndex: billingLinesEditableIndex, handleAdd: handleBillingLinesAdd, initialBillingLineData: initialBillingLineData, handleDelete: handleBillingLinesDelete, handleSave: handleBillingLinesSave })),
182
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
183
+ react_1.default.createElement(components_1.BaseInformation, { form: form, documentType: "invoice" })),
189
184
  react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
190
185
  react_1.default.createElement(components_1.PaymentMethod, null)),
191
- react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 16 } },
186
+ react_1.default.createElement(antd_1.Col, { xs: { span: 24 }, md: { span: 8 } },
192
187
  react_1.default.createElement(components_1.Attachments /*handleAddFile={handleAddFile}*/, null)),
193
188
  react_1.default.createElement(antd_1.Col, { span: 24 },
194
189
  react_1.default.createElement(antd_1.Form.Item, null,
@@ -8,11 +8,12 @@ interface Props extends InjectedIntlProps {
8
8
  setBillingLineMetadata: (formInstance: FormInstance, billingLineMetadata: BillingLineMetadata[]) => void;
9
9
  dataSource: BillingLineMetadataOverride[];
10
10
  handleDelete: (index: number) => void;
11
- handleAdd: () => void;
11
+ handleAdd: (billingLineToAdd: BillingLineMetadataOverride) => void;
12
12
  handleSave: (row: BillingLineMetadataOverride, formInstance: FormInstance) => void;
13
+ initialBillingLineData: BillingLineMetadataOverride;
13
14
  editableIndex: number;
14
15
  }
15
- declare const BillingLinesIntl: React.ComponentClass<Pick<Props, "formInstance" | "setBillingLineMetadata" | "dataSource" | "handleDelete" | "handleAdd" | "handleSave" | "editableIndex">, any> & {
16
+ declare const BillingLinesIntl: React.ComponentClass<Pick<Props, "formInstance" | "setBillingLineMetadata" | "dataSource" | "handleDelete" | "handleAdd" | "handleSave" | "initialBillingLineData" | "editableIndex">, any> & {
16
17
  WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
17
18
  };
18
19
  export default BillingLinesIntl;
@@ -1,6 +1,15 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { InjectedIntlProps } from "react-intl";
3
- declare const CustomerIntl: React.ComponentClass<Pick<InjectedIntlProps, never>, any> & {
4
- WrappedComponent: React.ComponentType<InjectedIntlProps>;
3
+ import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
4
+ import { FormInstance } from "antd/es/form";
5
+ import { PartyMetadata } from "@unimaze/api-clients/lib/mapi";
6
+ interface Props extends InjectedIntlProps {
7
+ customers: ProfileOutput[];
8
+ formInstance: FormInstance;
9
+ chosenCustomer: PartyMetadata | undefined;
10
+ setChosenCustomer: (chosenCustomer: PartyMetadata) => void;
11
+ }
12
+ declare const CustomerIntl: React.ComponentClass<Pick<Props, "chosenCustomer" | "setChosenCustomer" | "customers" | "formInstance">, any> & {
13
+ WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
5
14
  };
6
15
  export default CustomerIntl;
@@ -17,7 +17,7 @@ interface Props extends InjectedIntlProps {
17
17
  onlyLabelOnFirstInList?: boolean;
18
18
  index?: number;
19
19
  }
20
- declare const _default: React.ComponentClass<Pick<Props, "style" | "initialValue" | "receiverRequirementsKey" | "defaultLabel" | "defaultIsRequired" | "fieldName" | "additionalRules" | "verticalLabels" | "onlyLabelOnFirstInList" | "index">, any> & {
20
+ declare const _default: React.ComponentClass<Pick<Props, "style" | "initialValue" | "fieldName" | "receiverRequirementsKey" | "defaultLabel" | "defaultIsRequired" | "additionalRules" | "verticalLabels" | "onlyLabelOnFirstInList" | "index">, any> & {
21
21
  WrappedComponent: React.ComponentType<Props & InjectedIntlProps>;
22
22
  };
23
23
  export default _default;
@@ -3,7 +3,7 @@ import React from "react";
3
3
  import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
4
4
  import { CommonProps } from "../common/types/CommonProps";
5
5
  interface Props extends CommonProps {
6
- customer: ProfileOutput;
6
+ customers: ProfileOutput[];
7
7
  }
8
8
  /**
9
9
  * Component for creating a form for creating an invoice and submitting it to the MAPI transaction services
@@ -1,6 +1,8 @@
1
- import { BillingLineMetadata, InvoiceMetadataInput } from "@unimaze/api-clients/lib/mapi";
1
+ import { BillingLineMetadata, InvoiceMetadataInput, PartyMetadata } from "@unimaze/api-clients/lib/mapi";
2
2
  import { Store } from "antd/es/form/interface";
3
3
  import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
4
4
  import { PaymentMeansMetadata } from "@unimaze/api-clients/lib/mapi/api";
5
- declare const convertToInvoiceMetadataInput: (formValues: Store, billingLines: BillingLineMetadata[], paymentMethod: PaymentMeansMetadata, customer?: ProfileOutput | undefined) => InvoiceMetadataInput;
6
- export { convertToInvoiceMetadataInput };
5
+ declare const convertToInvoiceMetadataInput: (formValues: Store, billingLines: BillingLineMetadata[], paymentMethod: PaymentMeansMetadata, chosenCustomer: PartyMetadata) => InvoiceMetadataInput;
6
+ declare const profileOutputToPartyMetadata: (profileOutput: ProfileOutput) => PartyMetadata;
7
+ declare const convertToReadableKennitala: (isoIdentifier: string) => string;
8
+ export { convertToInvoiceMetadataInput, profileOutputToPartyMetadata, convertToReadableKennitala };
@@ -1,6 +1,8 @@
1
- import { BillingLineMetadata, InvoiceMetadataInput } from "@unimaze/api-clients/lib/mapi";
1
+ import { BillingLineMetadata, InvoiceMetadataInput, PartyMetadata } from "@unimaze/api-clients/lib/mapi";
2
2
  import { Store } from "antd/es/form/interface";
3
3
  import { ProfileOutput } from "@unimaze/api-clients/lib/wapi2";
4
4
  import { PaymentMeansMetadata } from "@unimaze/api-clients/lib/mapi/api";
5
- declare const convertToInvoiceMetadataInput: (formValues: Store, billingLines: BillingLineMetadata[], paymentMethod: PaymentMeansMetadata, customer?: ProfileOutput | undefined) => InvoiceMetadataInput;
6
- export { convertToInvoiceMetadataInput };
5
+ declare const convertToInvoiceMetadataInput: (formValues: Store, billingLines: BillingLineMetadata[], paymentMethod: PaymentMeansMetadata, chosenCustomer: PartyMetadata) => InvoiceMetadataInput;
6
+ declare const profileOutputToPartyMetadata: (profileOutput: ProfileOutput) => PartyMetadata;
7
+ declare const convertToReadableKennitala: (isoIdentifier: string) => string;
8
+ export { convertToInvoiceMetadataInput, profileOutputToPartyMetadata, convertToReadableKennitala };
@@ -44,7 +44,7 @@ var getIdentifierWithPrefix = function (identifier) {
44
44
  // const cleanIdentifier = (identifier: string): string => {
45
45
  // return identifier.replace(/[^0-9]/g, "") // replace anything that isn't a numeric character
46
46
  // }
47
- var convertToInvoiceMetadataInput = function (formValues, billingLines, paymentMethod, customer) {
47
+ var convertToInvoiceMetadataInput = function (formValues, billingLines, paymentMethod, chosenCustomer) {
48
48
  var issueDate = convertDates(formValues.invoice.issueDate);
49
49
  var dueDate = convertDates(formValues.invoice.dueDate);
50
50
  var referenceIdentifiersArray = formValues.invoice.referenceIdentifiers;
@@ -68,32 +68,32 @@ var convertToInvoiceMetadataInput = function (formValues, billingLines, paymentM
68
68
  value: referenceId.value
69
69
  }); })
70
70
  : null;
71
- var getMessageHandling = function (profileOutput) {
72
- if (!(profileOutput && profileOutput.participantLegalIsoIdentifier && profileOutput.email)) {
71
+ var getMessageHandling = function (partyMetadata) {
72
+ if (!(partyMetadata && partyMetadata.identifier && partyMetadata.contact && partyMetadata.contact.electronicMail)) {
73
73
  antd_1.message.error("There is an error in the configuration file for the receiver information");
74
74
  throw new Error("There is an error in the configuration file for the receiver information");
75
75
  }
76
76
  return {
77
- receiverIdentifier: profileOutput.participantLegalIsoIdentifier,
78
- fallbackEmailAddress: profileOutput.email,
79
- fallbackContactName: profileOutput.name
77
+ receiverIdentifier: partyMetadata.identifier,
78
+ fallbackEmailAddress: partyMetadata.contact.electronicMail,
79
+ fallbackContactName: partyMetadata.name
80
80
  };
81
81
  };
82
82
  var resp = {
83
- messageHandling: getMessageHandling(customer),
83
+ messageHandling: getMessageHandling(chosenCustomer),
84
84
  invoice: {
85
85
  customer: {
86
- identifier: getIdentifierWithPrefix(invoice.customer.identifier),
86
+ identifier: getIdentifierWithPrefix(chosenCustomer.identifier),
87
87
  address: {
88
- streetNameAndNumber: invoice.customer.address.streetNameAndNumber,
89
- postalZone: invoice.customer.address.postalZone,
90
- city: invoice.customer.address.city,
91
- countryCode: invoice.customer.address.countryCode
88
+ streetNameAndNumber: chosenCustomer.address.streetNameAndNumber,
89
+ postalZone: chosenCustomer.address.postalZone,
90
+ city: chosenCustomer.address.city,
91
+ countryCode: chosenCustomer.address.countryCode
92
92
  },
93
- name: invoice.customer.name,
93
+ name: chosenCustomer.name,
94
94
  contact: {
95
- electronicMail: invoice.customer.contact.electronicMail,
96
- telephone: invoice.customer.contact.telephone,
95
+ electronicMail: chosenCustomer.contact.electronicMail,
96
+ telephone: chosenCustomer.contact.telephone,
97
97
  }
98
98
  },
99
99
  supplier: {
@@ -131,3 +131,29 @@ var convertToInvoiceMetadataInput = function (formValues, billingLines, paymentM
131
131
  return resp;
132
132
  };
133
133
  exports.convertToInvoiceMetadataInput = convertToInvoiceMetadataInput;
134
+ var profileOutputToPartyMetadata = function (profileOutput) {
135
+ if (!profileOutput.participantLegalIsoIdentifier || !profileOutput.participantLegalAddressStreet || !profileOutput.name || !profileOutput.country) {
136
+ var errorMessage = "There was an error with the customer information, please check the application configuration";
137
+ antd_1.message.error(errorMessage);
138
+ throw new Error(errorMessage);
139
+ }
140
+ return {
141
+ identifier: profileOutput.participantLegalIsoIdentifier,
142
+ address: {
143
+ streetNameAndNumber: profileOutput.participantLegalAddressStreet,
144
+ city: profileOutput.participantLegalAddressCity,
145
+ countryCode: profileOutput.country,
146
+ postalZone: profileOutput.participantLegalAddressPostalCode
147
+ },
148
+ name: profileOutput.name,
149
+ contact: {
150
+ electronicMail: profileOutput.email,
151
+ telephone: profileOutput.phoneNumber
152
+ }
153
+ };
154
+ };
155
+ exports.profileOutputToPartyMetadata = profileOutputToPartyMetadata;
156
+ var convertToReadableKennitala = function (isoIdentifier) {
157
+ return isoIdentifier.substr(5, 6) + "-" + isoIdentifier.substr(11);
158
+ };
159
+ exports.convertToReadableKennitala = convertToReadableKennitala;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unimaze/billing",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",