From 9ca1864b79ede841e71836132effc2e260b4e758 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Fri, 11 Nov 2022 23:28:13 +0530 Subject: added very basic functionality to generate and list invoices --- src/App.js | 2 + src/classes/client.js | 4 +- src/classes/invoice.js | 49 +++++++++++++++- src/components/editors/invoice-headers-editor.js | 52 ++++++++++++----- src/components/tables/invoice-summary.js | 3 +- src/components/tables/invoice-table.js | 74 ++++++++++++++++++++++++ src/views/invoice/new.js | 44 ++++++++++++-- src/views/manage/invoices.js | 62 ++++++++++++++++++++ 8 files changed, 266 insertions(+), 24 deletions(-) create mode 100644 src/components/tables/invoice-table.js create mode 100644 src/views/manage/invoices.js (limited to 'src') diff --git a/src/App.js b/src/App.js index 1938304..a7a2e5c 100644 --- a/src/App.js +++ b/src/App.js @@ -24,6 +24,7 @@ import ManagementPage from './views/manage/manage'; import ManageItemsPage from './views/manage/items'; import ManageClientsPage from './views/manage/clients'; import ManageBrandsPage from './views/manage/brands'; +import ManageInvoicesPage from './views/manage/invoices'; const App = () => { return ( @@ -36,6 +37,7 @@ const App = () => { }/> }/> }/> + }/> }/> 404}/> diff --git a/src/classes/client.js b/src/classes/client.js index d05655d..baa2ed7 100644 --- a/src/classes/client.js +++ b/src/classes/client.js @@ -54,8 +54,8 @@ export class InvoiceClient extends Client { } } -export const saveClient = (item, ok, fail) => { - axios.post("/client/new", item) +export const saveClient = (client, ok, fail) => { + axios.post("/client/new", client) .then(res => ok(res)) .catch(err => fail(err)) } diff --git a/src/classes/invoice.js b/src/classes/invoice.js index 1032b47..066cbc3 100644 --- a/src/classes/invoice.js +++ b/src/classes/invoice.js @@ -15,7 +15,10 @@ * along with this program. If not, see . */ -//import axios from "axios"; +import { InvoiceItem } from "./item"; +import { Client, Address } from "./client"; + +import axios from "axios"; export class Transporter { constructor() { @@ -35,3 +38,47 @@ export class Transport { this.TransportMethod = ""; } } + +export class Invoice { + constructor() { + this.Id = null; + this.InvoiceNumber = 0; + this.TotalAmount = 0.00; + this.CreatedAt = new Date(); + this.LastUpdated = null; + this.Recipient = new Client(); + this.Paid = false; + this.TransactionId = ""; + this.Transport = new Transport(); + this.DiscountPercentage = 0; + this.BillingAddress = new Address(); + this.ShippingAddress = new Address(); + this.Items = []; + this.Note = ""; + this.Draft = true; + } +} + +export const getAllInvoices = (ok, fail) => { + axios.get("/invoice/all") + .then(res => ok(res.data)) + .catch(err => fail()) +} + +export const saveInvoice = (invoice, ok, fail) => { + axios.post("/invoice/new", invoice) + .then(res => ok(res)) + .catch(err => fail(err)) +} + +export const deleteInvoice = (id, ok, fail) => { + axios.delete(`/invoice/${id}`) + .then(res => ok()) + .catch((err) => fail()) +} + +export const editInvoice = (item, ok, fail) => { + axios.put(`/invoice/${item.Id}`, item) + .then(res => ok()) + .catch(err => fail()); +} 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