aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-11-11 23:28:13 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-11-11 23:28:13 +0530
commit9ca1864b79ede841e71836132effc2e260b4e758 (patch)
treedfb76a9cc85a6d7c21803cef842b530a48a2c2fa /src/components
parentb944cfb33efd63c335305f9535054ea4f02acd59 (diff)
added very basic functionality to generate and list invoices
Diffstat (limited to 'src/components')
-rw-r--r--src/components/editors/invoice-headers-editor.js52
-rw-r--r--src/components/tables/invoice-summary.js3
-rw-r--r--src/components/tables/invoice-table.js74
3 files changed, 113 insertions, 16 deletions
diff --git a/src/components/editors/invoice-headers-editor.js b/src/components/editors/invoice-headers-editor.js
index 4ab2dcc..d099e59 100644
--- a/src/components/editors/invoice-headers-editor.js
+++ b/src/components/editors/invoice-headers-editor.js
@@ -19,21 +19,25 @@ import './scss/invoice-headers.scss';
import { useState, useEffect } from 'react';
-const InvoiceHeadersEditor = ({roundOff, setRoundOff, transport, setTransport, transporter, setTransporter}) => {
- const handleTransportInput = e => {
+const InvoiceHeadersEditor = ({roundOff, setRoundOff, transport, setTransport}) => {
+ const handleInput = e => {
const { name, value } = e.target;
- setTransport(prev => ({
- ...prev,
- [name]: value
- }));
- }
- const handleTransporterInput = e => {
- const { name, value } = e.target;
- setTransporter(prev => ({
- ...prev,
- [name]: value
- }));
+ if (name.includes("Transporter.")) {
+ const n = name.split(".")[1];
+ const transporter = transport.Transporter;
+ transporter[n] = value;
+
+ setTransport(prev => ({
+ ...prev,
+ Transporter: transporter,
+ }));
+ } else {
+ setTransport(prev => ({
+ ...prev,
+ [name]: value
+ }));
+ }
}
return (
@@ -63,36 +67,54 @@ const InvoiceHeadersEditor = ({roundOff, setRoundOff, transport, setTransport, t
<label>
Vehicle Number:
<input
+ name="VehicleNum"
+ value={transport.VehicleNum}
+ onChange={handleInput}
type="text"/>
</label>
<label>
Transport Method:
<input
+ name="TransportMethod"
+ value={transport.TransportMethod}
+ onChange={handleInput}
type="text"/>
</label>
<label>
Transporter Name:
<input
+ name="Transporter.Name"
+ value={transport.Transporter.Name}
+ onChange={handleInput}
type="text"/>
</label>
<label>
Transporter GSTIN:
<input
+ name="Transporter.GSTIN"
+ value={transport.Transporter.GSTIN}
+ onChange={handleInput}
type="text"/>
</label>
<label>
Transporter ID:
<input
+ name="Transporter.TransporterId"
+ value={transport.Transporter.TransporterId}
+ onChange={handleInput}
type="text"/>
</label>
<label>
- Note:
- <textarea />
+ Delivery Note:
+ <textarea
+ name="Note"
+ value={transport.Note}
+ onChange={handleInput} />
</label>
</div>
</div>
diff --git a/src/components/tables/invoice-summary.js b/src/components/tables/invoice-summary.js
index a5c594f..75c2ddc 100644
--- a/src/components/tables/invoice-summary.js
+++ b/src/components/tables/invoice-summary.js
@@ -18,7 +18,7 @@
import './scss/summary.scss';
import { currency } from '../../classes/item';
-const InvoiceSummary = ({sum, roundOff}) => {
+const InvoiceSummary = ({sum, roundOff, submit}) => {
const totalRoundedOff = currency(sum.Amount !== undefined ? Math.round(sum.Amount.value) : 0.00);
const roundedOffDiff = sum.Amount !== undefined && roundOff ? sum.Amount.subtract(totalRoundedOff) : currency(0.00);
@@ -59,6 +59,7 @@ const InvoiceSummary = ({sum, roundOff}) => {
}
</tbody>
</table>
+ <button onClick={submit}>Generate Invoice</button>
</>
);
}
diff --git a/src/components/tables/invoice-table.js b/src/components/tables/invoice-table.js
new file mode 100644
index 0000000..3c37fe0
--- /dev/null
+++ b/src/components/tables/invoice-table.js
@@ -0,0 +1,74 @@
+/* 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 './scss/table.scss';
+import { deleteInvoice } from './../../classes/invoice';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
+import { faPencil, faTrashCan } from '@fortawesome/free-solid-svg-icons'
+
+const InvoiceTable = (props) => {
+ const handleEdit = (i) => {
+ props.setInvoiceToEdit(i)
+ }
+
+ const handleDelete = (i) => {
+ // TODO: add confirmation prompt
+ deleteInvoice(i.Id, handleDelSuccess, handleDelFail);
+ }
+
+ const handleDelSuccess = () => {
+ props.refresh();
+ }
+
+ const handleDelFail = () => {
+ alert("fail")
+ }
+
+ return (
+ <table className={"item-table"}>
+ <thead>
+ <tr>
+ <th>S. No</th>
+ <th>Invoice Number</th>
+ <th>Recipient Name</th>
+ <th>Date Created</th>
+ <th>Date Last Updated</th>
+ <th>Total Amount</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ {props.items && props.items.map((i, id) => (
+ <tr key={id}>
+ <td>{id+1}</td>
+ <td>{i.InvoiceNumber}</td>
+ <td>{i.Recipient.Name}</td>
+ <td>{i.CreatedAt}</td>
+ <td>{i.UpdatedAt}</td>
+ <td>{i.TotalAmount}</td>
+ <td className={"buttons"}>
+ <FontAwesomeIcon icon={faPencil} onClick={() => handleEdit(i)}/>
+ <FontAwesomeIcon icon={faTrashCan} onClick={() => handleDelete(i)}/>
+ </td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ );
+}
+
+export default InvoiceTable;