This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
123 lines (112 loc) · 3.19 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var express = require('express');
var app = express();
var db = require('./db');
var bodyParser = require('body-parser');
var multer = require('multer');
var upload = multer({dest: 'uploads/'});
//Configuration
app.set('views', './views');
app.set('view engine', 'pug');
//Default use
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(upload.array());
//Home page
app.get('/', function (req, res) {
res.render('home', {
title: 'Home page',
slogan: 'Have a nice day'
});
});
app.post('/', function (req, res) {
db.customerFinder(req.body, function (data) {
res.render('home', {
title: 'Home page',
slogan: 'All your customer here, have a nice day',
tableData: data
});
});
});
//Bill page
app.get('/bill', function (req, res) {
res.render('bill', {
title: 'Bill',
slogan: 'Every day is a happy day, works as hard as you can'
});
});
app.post('/bill', function (req, res) {
db.createInvoice(req.body);
res.redirect('/bill');
});
//Material page
app.get('/materialcost', function (req, res) {
res.render('materialcost', {
title: 'Material Costing',
slogan: 'Ingredient cost, this place control your money flow'
});
});
app.post('/materialcost', function (req, res) {
db.createMaterial(req.body);
res.redirect('/materialcost')
});
//Date report page
app.get('/datereport', function (req, res) {
res.render('datereport', {
title: 'Report by date',
slogan: 'Report by date'
});
});
app.post('/datereport', function (req, res) {
db.reportByDate(req.body, function (invoice) {
db.listAllProducts(function (listOfProducts) {
res.render('datereport', {
title: 'Report by date',
slogan: 'Report by date',
tableData: invoice,
allProduct: listOfProducts
});
});
});
});
app.put('/datereport', function (req, res) {
db.invoiceUpdate(req.body, function () {
res.status(200).end()
});
});
//Capital report page
app.get('/capitalreport', function (req, res) {
db.materialList(function (list) {
res.render('capitalreport', {
title: 'Capital report',
slogan: 'Choosing the best ingredients making the customer happier',
tableData: list
});
});
});
//Invoice report
app.get('/invoicereport', function (req, res) {
db.listAllInvoiceHaventTakenMoney(function (invoices) {
res.render('invoicereport', {
title: 'Invoice report',
slogan: 'This is the list of invoice haven\'t taken money',
tableData: invoices
});
})
});
app.put('/invoicereport', function (req, res) {
db.invoiceUpdate(req.body, function () {
res.status(200).end()
});
});
//Not official yet
app.post('/submit', function (req, res) {
var requestBody = JSON.parse(JSON.stringify(req.body));
console.log(requestBody);
});
//Start server
var server = app.listen(1993, function () {
console.log('Server has started on port ' + server.address().port);
db.authenticateConnection();
db.sync();
});