Skip to content

Commit

Permalink
serialized invoice numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
panshak committed Feb 6, 2022
1 parent 53b757b commit de3836b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 33 deletions.
6 changes: 1 addition & 5 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@

// Copyright: Panshak Solomon
// A.P. Leventis Ornithological Research Institute.
// University of Jos Biological Conservatory
// All right reserved
// ©2022 and beyond
//Copyright (c) 2022 Panshak Solomon

import React from 'react'
import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom'
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Footer/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Footer = () => {
return (
<footer>
<div className={styles.footerText}>
©Arc Invoice| made with ♥ by Panshak Solomon <span><a href="https://github.com/Panshak/arcinvoice" target="_blank" rel="noopener noreferrer">[Download source code]</a></span>
©Panshak Solomon | Made with ♥ in 🇳🇬 <span><a href="https://github.com/Panshak/arcinvoice" target="_blank" rel="noopener noreferrer">[Download source code]</a></span>
</div>
{user && (
<FabButton />
Expand Down
12 changes: 12 additions & 0 deletions client/src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MenuItem from '@material-ui/core/MenuItem';
import MenuList from '@material-ui/core/MenuList';
import { makeStyles } from '@material-ui/core/styles';
import Avatar from '@material-ui/core/Avatar';
import axios from 'axios'


const useStyles = makeStyles((theme) => ({
Expand All @@ -38,6 +39,17 @@ const Header = () => {
},[location])



useEffect(() => {
getMetaData()
},[])


const getMetaData = async() => {
const response = await axios.get('https://api.github.com/repos/panshak/arc')
console.log(response.data);
}

const logout =() => {
dispatch({ type: 'LOGOUT' })
history.push('/')
Expand Down
33 changes: 25 additions & 8 deletions client/src/components/Invoice/Invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ const Invoice = () => {
try {
const response = await axios.get(`${process.env.REACT_APP_API}/invoices/count?searchQuery=${user?.result?._id}`);
// console.log(response.data);
setInvoiceData({...invoiceData, invoiceNumber: (response?.data)})
setInvoiceData({...invoiceData, invoiceNumber: (Number(response.data) + 1).toString().padStart(3, '0')})
} catch (error) {
console.error(error);
}
}




Expand Down Expand Up @@ -237,8 +238,8 @@ const Invoice = () => {
dueDate: selectedDate,
invoiceNumber: `${
invoiceData.invoiceNumber < 100 ?
(Number(invoiceData.invoiceNumber) + 1).toString().padStart(3, '0')
: Number(invoiceData.invoiceNumber) + 1
(Number(invoiceData.invoiceNumber)).toString().padStart(3, '0')
: Number(invoiceData.invoiceNumber)
}`,
client,
type: type,
Expand Down Expand Up @@ -277,11 +278,27 @@ const Invoice = () => {
</Grid>
<Grid item>
<InvoiceType type={type} setType={setType} />
<p style={{color: 'gray'}}> Invoice#:
<span
style={{paddingLeft: '20px', paddingRight: '20px'}}
contentEditable
onInput={e => setInvoiceData({...invoiceData, invoiceNumber: e.currentTarget.textContent})}>{invoice ? invoiceData.invoiceNumber : (Number(invoiceData.invoiceNumber) + 1).toString().padStart(3, '0')}</span></p>
Invoice #:
<div style={{
marginTop: '15px',
width: '100px',
padding: '8px',
display: 'inline-block',
backgroundColor: '#f4f4f4',
outline: '0px solid transparent'
}}
contenteditable="true"
onInput={e => setInvoiceData({
...invoiceData, invoiceNumber: e.currentTarget.textContent})
}
>
<span style={{width:'40px',
color: 'black',
padding: '15px',
}}
contenteditable="false"> {invoiceData.invoiceNumber}</span>
<br/>
</div>
</Grid>
</Grid >
</Container>
Expand Down
6 changes: 1 addition & 5 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Copyright: Panshak Solomon
// A.P. Leventis Ornithological Research Institute.
// University of Jos Biological Conservatory
// All right reserved
// ©2022 and beyond
//Copyright (c) 2022 Panshak Solomon

import React from 'react';
import ReactDOM from 'react-dom';
Expand Down
11 changes: 2 additions & 9 deletions server/controllers/invoices.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// Copyright: Panshak Solomon
// A.P. Leventis Ornithological Research Institute.
// University of Jos Biological Conservatory
// All right reserved
// ©2022 and beyond

//Copyright (c) 2022 Panshak Solomon

import express from 'express'
import mongoose from 'mongoose'

import InvoiceModel from '../models/InvoiceModel.js'


export const getInvoicesByUser = async (req, res) => {
const {searchQuery} = req.query;

try {
const invoices = await InvoiceModel.find({ creator: searchQuery });
// const invoices = await InvoiceModel.find().where('creator').in(searchQuery);

res.status(200).json({ data: invoices });
} catch (error) {
Expand All @@ -38,12 +33,10 @@ export const getTotalCount = async (req, res) => {
}



export const getInvoices = async (req, res) => {

try {
const allInvoices = await InvoiceModel.find({}).sort({_id:-1})
//find({}).sort({_id:-1}) to sort according to date of creation

res.status(200).json(allInvoices)

Expand Down
8 changes: 3 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

//Copyright (c) 2022 Panshak Solomon

import express from 'express'
import cors from 'cors'
import mongoose from 'mongoose'
Expand All @@ -14,11 +17,6 @@ const __dirname = dirname(__filename);
import invoiceRoutes from './routes/invoices.js'
import clientRoutes from './routes/clients.js'
import userRoutes from './routes/userRoutes.js'
// Copyright: Panshak Solomon
// A.P. Leventis Ornithological Research Institute.
// University of Jos Biological Conservatory
// All right reserved
// ©2022 and beyond

import profile from './routes/profile.js'
import pdfTemplate from './documents/index.js'
Expand Down

0 comments on commit de3836b

Please sign in to comment.