Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
67 changes: 67 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<html>

<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function () {
$("input[type='button']").click(function () {
var radioValue = $("input[name='type']:checked").val();
if (radioValue == "text") {
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:3000/",
"method": "POST",
"headers": {
"Content-Type": "text/plain",
"cache-control": "no-cache",
},
"data": document.getElementById('data').value
}
$.ajax(settings).done(function (response) {
console.log(response);
str = "";
for (let i = 0; i < response.stmt.length; i++) {
str += response.stmt[i] + "<br>"
}
document.getElementById('output').innerHTML = `<p>${response.name}:<br> ${str}Sales:${response.sales}<br>Total:${response.total}</p>`;
//console.log(`${response.name}:\n ${str} \n Sales:${response.sales}\n Total:${response.total}`);
});
}
else {
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost:3000/",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"cache-control": "no-cache",
},
"data": document.getElementById('data').value
}
$.ajax(settings).done(function (response) {
console.log(response)
str = "";
for (let i = 0; i < response.stmt.length; i++) {
str += response.stmt[i] + "<br>"
}
document.getElementById('output').innerHTML = `<p>${response.name}:<br> ${str}Sales:${response.sales}<br>Total:${response.total}</p>`;
//console.log(`${response.name}:\n ${str} \n Sales:${response.sales}\n Total:${response.total}`);
});
}
});
});
</script>
</head>

<body>

<input type="radio" name="type" value="json" />json
<input type="radio" name="type" value="text" />text
<input type="text" name="data" id="data">
<input type="button" value="Get Value">
<p id="output" ></pid>
</body>

</html>
77 changes: 77 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const express = require('express');
const bodyParser = require('body-parser')
const app = express();
const tax = require('./sales_imported');
const text_tax = require('./sales_imported_text');
app.use("/", bodyParser.json());
app.use("/", bodyParser.text())
app.get("/", function (req, res) {
console.count('homepage');
res.sendFile('/home/asd/myapp/index.html', function (err) {
if (err) {
console.log(err);
}
});
});
app.post('/', function (req, res, next) {
if (req.headers["content-type"] == "application/json") {
console.log(req.headers["content-type"])
var array = req.body.items;
var str = []
let total = 0;
let sales = 0;
console.dir(array);
for (let i = 0; i < array.length; i++) {
str.push(`${array[i].quantity} ${tax.isimported(array[i])} ${array[i].name}: ${array[i].price + tax.salestax(array[i]) + tax.importtax(array[i])}`);
sales += tax.salestax(array[i]) + tax.importtax(array[i]);
total += array[i].price + tax.salestax(array[i]) + tax.importtax(array[i]);
}
console.dir(str);
console.log(total);
res.json({
"name": req.body.name,
"stmt": str,
"total": total,
"sales": sales
});
console.log(res.body);
res.end();
} if (req.headers["content-type"] == "text/plain") {
console.log(2121212);
next();
}
}, function (req, res) {
let str = req.body;
console.dir(str);
orderNo = str.split(":");
sentences = orderNo[1].split("\\n");
quantity = [];
body = [];
price = [];
for (let i = 1; i < sentences.length; i++) {
regex = new RegExp('(\\d+)');
temp = sentences[i].split(regex);
quantity.push(temp[1]);
lastind = temp[2].lastIndexOf("at");
body.push(temp[2].substr(0, lastind) + ":");
price.push(temp[3] + temp[4] + temp[5]);
}
stmt = [];
total = 0;
sales = 0
for (let i = 1; i < sentences.length; i++) {
sales += text_tax.sales_tax(quantity[i - 1], body[i - 1], price[i - 1]) + text_tax.imported_tax(quantity[i - 1], body[i - 1], price[i - 1]);
aftertax = parseFloat(price[i - 1]) + text_tax.sales_tax(quantity[i - 1], body[i - 1], price[i - 1]) + text_tax.imported_tax(quantity[i - 1], body[i - 1], price[i - 1]);
stmt.push(`${quantity[i - 1]} ${body[i - 1]} ${aftertax}`);
total += aftertax;
}
res.json({
"name": orderNo[0],
"stmt": stmt,
"total": total,
"sales": sales
});
console.log(res.body);
res.end("hello");
});
app.listen(3000);
1 change: 1 addition & 0 deletions node_modules/.bin/atob

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/is-ci

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nodetouch

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nopt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/rc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions node_modules/abbrev/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions node_modules/abbrev/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions node_modules/abbrev/abbrev.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions node_modules/abbrev/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading