1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/* OpenBills-web - Web based libre billing software
* Copyright (C) 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Item, InvoiceItem, getAllItems } from '../../classes/item';
import './scss/item-picker.scss';
import { useState, useEffect } from 'react';
//import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
//import { faPhone, faEnvelope, faGlobe } from '@fortawesome/free-solid-svg-icons'
const ItemPicker = () => {
const [items, setItems] = useState([new Item()]);
const [item, setItem] = useState(new InvoiceItem());
useEffect(() => refreshItems, []);
const refreshItems = () =>
getAllItems(setItems, () => {});
const handleItemSelect = e => {
const i = items.find(i => i.Id === e.target.value);
setItem(prevItem => i ? ({...prevItem, ...i}) : new InvoiceItem());
}
const handleInput = e => {
const { name, value } = e.target;
setItem(prevItem => ({
...prevItem,
[name]: value
}));
}
return (
<div className={"picker-wrapper"}>
<p className={"heading"}>Add an Item</p>
<div className={"item-picker"}>
{items && items.length > 0 &&
<>
<label>
Product/Service:
<select value={item.Id ? item.Id : ""} onChange={handleItemSelect}>
<option key="placeholder" value={""} disabled>Select an Item</option>
{items.map(i =>
<option key={i.Id} value={i.Id}>{i.Name}{i.Brand.Id === null ? "" : " - " + i.Brand.Name}</option>
)}
</select>
</label>
<label>
Description:
<input
type="text"
value={item.Description}
name="Description"
onChange={handleInput} />
</label>
<label>
Quantity:
<input
type="number"
value={item.Quantity}
name="Quantity"
min={item.MinQuantity}
max={item.MaxQuantity}
onChange={handleInput} />
</label>
<label>
Price:
<input
type="number"
value={item.UnitPrice}
name="UnitPrice"
onChange={handleInput} />
</label>
<label>
Discount %:
<input
type="number"
value={item.DiscountPercentage}
name="DiscountPercentage"
onChange={handleInput} />
</label>
<label>
HSN:
<input
className={"narrow"}
type="text"
value={item.HSN}
name="HSN"
onChange={handleInput} />
</label>
<label>
GST %:
<input
type="number"
value={item.GSTPercentage}
name="GSTPercentage"
onChange={handleInput} />
</label>
</>
}
</div>
<hr/>
</div>
);
}
export default ItemPicker;
|