aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/database/database.go15
-rw-r--r--server/database/people.go70
-rw-r--r--src/components/Form/Document/DocumentInfoForm.tsx19
-rw-r--r--src/components/Form/People/RegisterPersonForm.tsx149
-rw-r--r--src/components/Form/People/SelectClientForm.tsx16
-rw-r--r--src/components/Pages/BillingPage.tsx15
-rw-r--r--src/interfaces.ts12
7 files changed, 219 insertions, 77 deletions
diff --git a/server/database/database.go b/server/database/database.go
index 68c3c76..a7a4f34 100644
--- a/server/database/database.go
+++ b/server/database/database.go
@@ -44,9 +44,18 @@ func InitDB() {
Name TEXT,
Phone TEXT,
Email TEXT,
- BillAddress BLOB,
- ShipAddress BLOB,
- GSTIN TEXT)`,
+
+ BillAddressLine TEXT,
+ BillAddressCity TEXT,
+ BillAddressState TEXT,
+ BillAddressPINCode TEXT,
+ BillAddressCountry TEXT,
+
+ ShipAddressLine TEXT,
+ ShipAddressCity TEXT,
+ ShipAddressState TEXT,
+ ShipAddressPINCode TEXT,
+ ShipAddressCountry TEXT)`,
)
init_people.Exec()
diff --git a/server/database/people.go b/server/database/people.go
index 25aa393..f0b05b8 100644
--- a/server/database/people.go
+++ b/server/database/people.go
@@ -4,13 +4,14 @@
* Licensed under the MIT license - https://opensource.org/licenses/MIT
*
* Copyright (c) 2021 Vidhu Kant Sharma
-*/
+ */
// handles all People related database functions
-package database
+package database
import (
- _ "github.com/mattn/go-sqlite3"
+ _ "github.com/mattn/go-sqlite3"
+ "fmt"
)
@@ -22,38 +23,85 @@ type Person struct {
Email string
BillAddress Address
ShipAddress Address
- GSTIN string
}
func GetAllPeople() []Person {
var allPeople []Person
rows, _ := myDatabase.Query (
- `SELECT ID, Name, Phone, Email, BillAddress, ShipAddress, GSTIN FROM People`,
+ `SELECT ID, Name, Phone, Email,
+
+ BillAddressLine, BillAddressCity,
+ BillAddressState, BillAddressPINCode,
+ BillAddressCountry,
+
+ ShipAddressLine,
+ ShipAddressCity, ShipAddressState,
+ ShipAddressPINCode, ShipAddressCountry
+
+ FROM People`,
)
var (
id int
- name, phone, email, gstin string
+ name, phone, email string
+ billAddressLine, billAddressCity, billAddressState, billAddressPINCode, billAddressCountry string
+ shipAddressLine, shipAddressCity, shipAddressState, shipAddressPINCode, shipAddressCountry string
billAddress, shipAddress Address
)
for rows.Next() {
- rows.Scan(&id, &name, &phone, &email, &billAddress, &shipAddress, &gstin)
- allPeople = append(allPeople, Person{id, name, phone, email, billAddress, shipAddress, gstin})
+ rows.Scan(
+ &id, &name, &phone, &email,
+
+ &billAddressLine, &billAddressCity,
+ &billAddressState, &billAddressPINCode,
+ &billAddressCountry,
+
+ &shipAddressLine, &shipAddressCity,
+ &shipAddressState, &shipAddressPINCode,
+ &shipAddressCountry,
+ )
+
+ billAddress = Address{billAddressLine, billAddressCity, billAddressState, billAddressPINCode, billAddressCountry}
+ shipAddress = Address{shipAddressLine, shipAddressCity, shipAddressState, shipAddressPINCode, shipAddressCountry}
+
+ allPeople = append(allPeople, Person{id, name, phone, email, billAddress, shipAddress})
+ fmt.Println(allPeople)
}
return allPeople
}
func RegisterPerson(person Person) bool {
+ fmt.Println(person)
register_person, _ := myDatabase.Prepare(
`INSERT INTO People
- (Name, Phone, Email, BillAddress, ShipAddress, GSTIN)
- VALUES (?, ?, ?, ?, ?, ?)`,
+ (Name, Phone, Email,
+
+ BillAddressLine, BillAddressCity,
+ BillAddressState, BillAddressPINCode,
+ BillAddressCountry,
+
+ ShipAddressLine, ShipAddressCity,
+ ShipAddressState, ShipAddressPINCode,
+ ShipAddressCountry)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
)
register_person.Exec(
- person.Name, person.Phone, person.Email, person.BillAddress, person.ShipAddress, person.GSTIN,
+ person.Name, person.Phone, person.Email,
+
+ person.BillAddress.AddressLine,
+ person.BillAddress.City,
+ person.BillAddress.State,
+ person.BillAddress.PINCode,
+ person.BillAddress.Country,
+
+ person.ShipAddress.AddressLine,
+ person.ShipAddress.City,
+ person.ShipAddress.State,
+ person.ShipAddress.PINCode,
+ person.ShipAddress.Country,
)
return true
diff --git a/src/components/Form/Document/DocumentInfoForm.tsx b/src/components/Form/Document/DocumentInfoForm.tsx
index 6135b33..2d7dcd9 100644
--- a/src/components/Form/Document/DocumentInfoForm.tsx
+++ b/src/components/Form/Document/DocumentInfoForm.tsx
@@ -25,12 +25,31 @@ interface Props {
}
const DocumentInfoForm: React.FC<Props> = (props) => {
+ const dummyPerson: Person = {
+ Name: "",
+ Address: "",
+ Phone: "",
+ Email: "",
+
+ BillAddress: {
+ AddressLine: "",
+ City: "",
+ State: "",
+ PINCode: "",
+ Country: "India" // TODO: Get default from server
+ }
+ }
+
const [invoiceNumber, setInvoiceNumber] = useState<number>(props.invoiceNumber);
const [invoiceDate, setInvoiceDate] = useState(new Date());
+ const [selectedClient, setSelectedClient] = useState<Person>(dummyPerson);
+
return (
<div className={"DocumentInfoForm"}>
<SelectClientForm
savedPeople={props.savedPeople}
+ selectedClient={selectedClient}
+ setSelectedClient={setSelectedClient}
/>
<div className={"documentInfoChild"}>
diff --git a/src/components/Form/People/RegisterPersonForm.tsx b/src/components/Form/People/RegisterPersonForm.tsx
index 9e3b155..3922975 100644
--- a/src/components/Form/People/RegisterPersonForm.tsx
+++ b/src/components/Form/People/RegisterPersonForm.tsx
@@ -8,7 +8,7 @@
import React, { useState } from "react";
import "./../Form.scss";
-import { Person } from "./../../../interfaces"
+import { Person, Address } from "./../../../interfaces"
import axios from "axios";
interface props {
@@ -18,9 +18,14 @@ interface props {
const RegisterPersonForm: React.FC<props> = (props) => {
const [newPersonName, setNewPersonName] = useState<string>("");
- const [newPersonAddress, setNewPersonAddress] = useState<string>("");
- const [newPersonEmail, setNewPersonEmail] = useState<string>("");
const [newPersonPhone, setNewPersonPhone] = useState<string>("");
+ const [newPersonEmail, setNewPersonEmail] = useState<string>("");
+
+ const [newPersonBillAddressLine, setNewPersonBillAddressLine] = useState<string>("");
+ const [newPersonBillCity, setNewPersonBillCity] = useState<string>("");
+ const [newPersonBillState, setNewPersonBillState] = useState<string>("");
+ const [newPersonBillPINCode, setNewPersonBillPINCode] = useState<string>("");
+ const [newPersonBillCountry, setNewPersonBillCountry] = useState<string>("");
const hideSelf = () => props.setVisibility(false);
@@ -32,9 +37,25 @@ const RegisterPersonForm: React.FC<props> = (props) => {
const newClient: Person = {
Name: newPersonName,
- Address: newPersonAddress,
Phone: newPersonPhone,
- Email: newPersonEmail
+ Email: newPersonEmail,
+
+ BillAddress: {
+ AddressLine: newPersonBillAddressLine,
+ City: newPersonBillCity,
+ State: newPersonBillState,
+ PINCode: newPersonBillPINCode,
+ Country: newPersonBillCountry
+ },
+
+ // currently same as BillAddress
+ ShipAddress: {
+ AddressLine: newPersonBillAddressLine,
+ City: newPersonBillCity,
+ State: newPersonBillState,
+ PINCode: newPersonBillPINCode,
+ Country: newPersonBillCountry
+ },
}
// TODO: show confirmation before being invisible
@@ -57,46 +78,84 @@ const RegisterPersonForm: React.FC<props> = (props) => {
<div className={"floatingMenu"}>
<div className={"formContainer"}>
<form className={"floatingForm"} onSubmit={postForm}>
- <div className={"wideForm"}>
- <label>
- Name: <input className={"wideInputBox"}
- type="text" value={newPersonName} onChange={
- (event) => setNewPersonName(event.target.value)
- }
- required />
- </label>
-
- <label>
- Phone: <input className={"wideInputBox"}
- type="text" value={newPersonPhone} onChange={
- (event) => setNewPersonPhone(event.target.value)
- }
- required />
- </label>
-
- <label>
- Email: <input className={"wideInputBox"}
- type="text" value={newPersonEmail} onChange={
- (event) => setNewPersonEmail(event.target.value)
- }
- required />
- </label>
-
- <label>
- Address: <input className={"wideInputBox"}
- type="text" value={newPersonAddress} onChange={
- (event) => setNewPersonAddress(event.target.value)
- }
- required />
- </label>
- </div>
-
- <div className={"menu"}>
- <input type="button" value="cancel"
- onClick={() => hideSelf()} />
-
- <input type="submit" value="Register/Add"
- disabled={newPersonName === "" ? true : false} />
+ <div className={"twoPaneForm"}>
+ <div className={"widePane formPane"}>
+ <label>
+ Name: <input className={"wideInputBox"}
+ type="text" value={newPersonName} onChange={
+ (event) => setNewPersonName(event.target.value)
+ }
+ required />
+ </label>
+
+ <label>
+ Phone: <input className={"wideInputBox"}
+ type="text" value={newPersonPhone} onChange={
+ (event) => setNewPersonPhone(event.target.value)
+ }
+ required />
+ </label>
+
+ <label>
+ Email: <input className={"wideInputBox"}
+ type="text" value={newPersonEmail} onChange={
+ (event) => setNewPersonEmail(event.target.value)
+ }
+ required />
+ </label>
+ </div>
+
+ <div className={"widePane formPane"}>
+ <h3>Billing Address</h3>
+
+ <label>
+ Address: <input className={"wideInputBox"}
+ type="text" value={newPersonBillAddressLine} onChange={
+ (event) => setNewPersonBillAddressLine(event.target.value)
+ }
+ required />
+ </label>
+
+ <label>
+ City: <input className={"wideInputBox"}
+ type="text" value={newPersonBillCity} onChange={
+ (event) => setNewPersonBillCity(event.target.value)
+ }
+ required />
+ </label>
+
+ <label>
+ State: <input className={"wideInputBox"}
+ type="text" value={newPersonBillState} onChange={
+ (event) => setNewPersonBillState(event.target.value)
+ }
+ required />
+ </label>
+
+ <label>
+ PIN Code: <input className={"wideInputBox"}
+ type="text" value={newPersonBillPINCode} onChange={
+ (event) => setNewPersonBillPINCode(event.target.value)
+ }
+ required />
+ </label>
+
+ <label>
+ Country: <input className={"wideInputBox"}
+ type="text" value={newPersonBillCountry} onChange={
+ (event) => setNewPersonBillCountry(event.target.value)
+ }
+ required />
+ </label>
+ </div>
+
+ <div className={"menu"}>
+ <input type="button" value="cancel"
+ onClick={() => hideSelf()} />
+
+ <input type="submit" value="Register/Add"
+ disabled={newPersonName === "" ? true : false} />
+ </div>
</div>
</form>
</div>
diff --git a/src/components/Form/People/SelectClientForm.tsx b/src/components/Form/People/SelectClientForm.tsx
index f91bf41..ca984ca 100644
--- a/src/components/Form/People/SelectClientForm.tsx
+++ b/src/components/Form/People/SelectClientForm.tsx
@@ -6,7 +6,7 @@
* Copyright (c) 2021 Vidhu Kant Sharma
*/
-import React, { useState } from "react";
+import React, { Dispatch, SetStateAction } from "react";
import { Person } from "./../../../interfaces";
import "./../Form.scss";
@@ -14,19 +14,19 @@ import ClientInfoDisplay from "../../Display/ClientInfoDisplay";
interface Props {
savedPeople: Person[]
+ selectedClient: Person
+ setSelectedClient: Dispatch<SetStateAction<Person>>
}
const SelectClientForm: React.FC<Props> = (props) => {
- // TODO: fix the default selectedClient
- const [selectedClient, setSelectedClient] = useState<Person>({Name: "", Address: ""});
-
const enterValuePrompt = "start typing here";
const registerPrompt = "add new";
// TODO: make it use email if no address found, shorten the name too
// in short, make formatter flexible
const formatter = (i: Person): string =>
- `${i.Name} - ${i.Address.slice(0, 20).concat(i.Address.length < 20 ? "" : "")}`;
+ // TODO: this shit is ugly
+ `${i.Name} - ${i.BillAddress.AddressLine.slice(0, 20).concat(i.BillAddress.AddressLine.length < 20 ? "" : "")}`;
// TODO: if no client found at least clear the display
// do this in other components too
@@ -35,7 +35,7 @@ const SelectClientForm: React.FC<Props> = (props) => {
(props.savedPeople === null || e === registerPrompt)
? alert("coming soon") // toggle registerPersonPrompt visibility
: props.savedPeople.some((i) =>
- e === formatter(i) && setSelectedClient(i))
+ e === formatter(i) && props.setSelectedClient(i))
return (
<div className={"documentInfoChild"}>
@@ -43,7 +43,7 @@ const SelectClientForm: React.FC<Props> = (props) => {
Client Name:
<select
className={"selectInputBox"}
- value={selectedClient.Name}
+ value={props.selectedClient.Name}
onChange={
(event) => {
setClientInfo(event.target.value);
@@ -59,7 +59,7 @@ const SelectClientForm: React.FC<Props> = (props) => {
</select>
</label>
- <ClientInfoDisplay client={selectedClient}/>
+ <ClientInfoDisplay client={props.selectedClient}/>
</div>
)
}
diff --git a/src/components/Pages/BillingPage.tsx b/src/components/Pages/BillingPage.tsx
index 58fdd40..9dcb485 100644
--- a/src/components/Pages/BillingPage.tsx
+++ b/src/components/Pages/BillingPage.tsx
@@ -56,13 +56,6 @@ const BillingPage: React.FC = () => {
// update the items from AddNewItemForm
const getItems = (item: Item) => setItems([...items, item]);
- const handleSubmit = () => {
- setShowSubmitMenu(true);
- axios.post(`/api/invoices/preview`, {ID: 1010, Items: items, Transporter: transporter})
- .then(() => alert("yay"))
- .catch(() => alert("nay"));
- }
-
return (
<>
{registerItemFormVisibility &&
@@ -83,8 +76,8 @@ const BillingPage: React.FC = () => {
{showTransportForm &&
<TransportForm
setVisibility={setShowTransportForm}
- currentTransporter={transporter}
setTransporter={setTransporter}
+ currentTransporter={transporter}
/>
}
@@ -119,8 +112,12 @@ const BillingPage: React.FC = () => {
<InvoiceInfoMenu
setShowTransportForm={setShowTransportForm}
/>
+
+ <button onClick={() => setShowSubmitMenu(true)}>
+ post (experimental)
+ </button>
+
<SummaryDisplay items={items}/>
- <button onClick={handleSubmit}>post (experimental)</button>
</div>
</>
);
diff --git a/src/interfaces.ts b/src/interfaces.ts
index 3500c2b..b2f354c 100644
--- a/src/interfaces.ts
+++ b/src/interfaces.ts
@@ -34,12 +34,22 @@ export interface NewItem {
// category and brand
}
+export interface Address {
+ AddressLine: string
+ City: string
+ State: string
+ PINCode: string
+ Country: string
+}
+
export interface Person {
ID?: number
Name: string
- Address: string
Phone?: string
Email?: string
+ BillAddress: Address
+ ShipAddress?: Address
+ Address?: string // to be removed
}
export interface Invoice {