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/classes/invoice.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/classes/invoice.js') 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()); +} -- cgit v1.2.3