@@ -29,14 +29,16 @@ export function FormDatePicker({
|
||||
|
||||
const handleChange = (newDate) => {
|
||||
if (value !== newDate && onChange) {
|
||||
onChange(newDate);
|
||||
console.log(newDate.tz(bodyshop.timezone));
|
||||
onChange(newDate.tz(bodyshop.timezone));
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
if (e.key.toLowerCase() === "t") {
|
||||
if (onChange) {
|
||||
onChange(moment());
|
||||
console.log(moment().tz(bodyshop.timezone));
|
||||
onChange(moment().tz(bodyshop.timezone));
|
||||
// if (ref.current && ref.current.blur) ref.current.blur();
|
||||
}
|
||||
} else if (e.key.toLowerCase() === "enter") {
|
||||
@@ -71,10 +73,11 @@ export function FormDatePicker({
|
||||
<div onKeyDown={handleKeyDown}>
|
||||
<DatePicker
|
||||
ref={ref}
|
||||
value={value ? moment(value) : null}
|
||||
value={value ? moment(value).tz(bodyshop.timezone) : null}
|
||||
onChange={handleChange}
|
||||
format={dateFormat}
|
||||
onBlur={onBlur || handleBlur}
|
||||
showToday={false}
|
||||
disabledTime
|
||||
{...(onlyFuture && {
|
||||
disabledDate: (d) => moment().subtract(1, "day").isAfter(d),
|
||||
|
||||
5325
package-lock.json
generated
Normal file
5325
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -35,6 +35,7 @@
|
||||
"graylog2": "^0.2.1",
|
||||
"inline-css": "^3.0.0",
|
||||
"intuit-oauth": "^4.0.0",
|
||||
"json-2-csv": "^3.17.0",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.29.1",
|
||||
"moment-timezone": "^0.5.34",
|
||||
|
||||
@@ -177,12 +177,18 @@ var data = require("./server/data/data");
|
||||
app.post("/data/ah", data.autohouse);
|
||||
app.post("/data/arms", data.arms);
|
||||
|
||||
var taskHandler = require("./server/tasks/tasks");
|
||||
app.post("/taskHandler", taskHandler.taskHandler);
|
||||
|
||||
|
||||
var ioevent = require("./server/ioevent/ioevent");
|
||||
app.post("/ioevent", ioevent.default);
|
||||
app.post("/newlog", (req, res) => {
|
||||
const { message, type, user, record, object } = req.body;
|
||||
logger.log(message, type, user, record, object);
|
||||
});
|
||||
|
||||
|
||||
var cdkGetMake = require("./server/cdk/cdk-get-makes");
|
||||
app.post("/cdk/getvehicles", fb.validateFirebaseIdToken, cdkGetMake.default);
|
||||
|
||||
|
||||
@@ -45,6 +45,25 @@ exports.sendServerEmail = async function ({ subject, text }) {
|
||||
logger.log("server-email-failure", "error", null, null, error);
|
||||
}
|
||||
};
|
||||
exports.sendTaskEmail = async function ({ to, subject, text, attachments }) {
|
||||
try {
|
||||
transporter.sendMail(
|
||||
{
|
||||
from: `ImEX Online <noreply@imex.online>`,
|
||||
to: to,
|
||||
subject: subject,
|
||||
text: text,
|
||||
attachments: attachments || null,
|
||||
},
|
||||
(err, info) => {
|
||||
console.log(err || info);
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
logger.log("server-email-failure", "error", null, null, error);
|
||||
}
|
||||
};
|
||||
|
||||
exports.sendEmail = async (req, res) => {
|
||||
logger.log("send-email", "DEBUG", req.user.email, null, {
|
||||
|
||||
@@ -77,6 +77,8 @@ async function JobCostingMulti(req, res) {
|
||||
totalLaborGppercentFormatted: null,
|
||||
totalPartsGppercent: null,
|
||||
totalPartsGppercentFormatted: null,
|
||||
totalAdditionalGppercent: null,
|
||||
totalAdditionalGppercentFormatted: null,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -178,6 +180,10 @@ async function JobCostingMulti(req, res) {
|
||||
multiSummary.summaryData.totalPartsGp.add(
|
||||
costingData.summaryData.totalPartsGp
|
||||
);
|
||||
multiSummary.summaryData.totalAdditionalGp =
|
||||
multiSummary.summaryData.totalAdditionalGp.add(
|
||||
costingData.summaryData.totalAdditionalGp
|
||||
);
|
||||
|
||||
//Take the summary data & add it to total summary data.
|
||||
});
|
||||
@@ -198,10 +204,21 @@ async function JobCostingMulti(req, res) {
|
||||
multiSummary.summaryData.totalPartsSales.getAmount()) *
|
||||
100
|
||||
).toFixed(2);
|
||||
|
||||
multiSummary.summaryData.totalPartsGppercentFormatted = formatGpPercent(
|
||||
multiSummary.summaryData.totalPartsGppercent
|
||||
);
|
||||
|
||||
multiSummary.summaryData.totalAdditionalGppercent = (
|
||||
(multiSummary.summaryData.totalAdditionalGp.getAmount() /
|
||||
multiSummary.summaryData.totalAdditionalSales.getAmount()) *
|
||||
100
|
||||
).toFixed(2);
|
||||
|
||||
multiSummary.summaryData.totalAdditionalGppercentFormatted = formatGpPercent(
|
||||
multiSummary.summaryData.totalAdditionalGppercent
|
||||
);
|
||||
|
||||
multiSummary.summaryData.gppercent = (
|
||||
(multiSummary.summaryData.gpdollars.getAmount() /
|
||||
multiSummary.summaryData.totalSales.getAmount()) *
|
||||
@@ -579,6 +596,8 @@ function GenerateCostingData(job) {
|
||||
totalLaborGppercentFormatted: null,
|
||||
totalPartsGppercent: null,
|
||||
totalPartsGppercentFormatted: null,
|
||||
totalAdditionalGppercent: null,
|
||||
totalAdditionalGppercentFormatted: null,
|
||||
gppercent: null,
|
||||
gppercentFormatted: null,
|
||||
};
|
||||
@@ -695,6 +714,17 @@ function GenerateCostingData(job) {
|
||||
summaryData.totalPartsGppercentFormatted = formatGpPercent(
|
||||
summaryData.totalPartsGppercent
|
||||
);
|
||||
summaryData.totalAdditionalGp = summaryData.totalAdditionalSales.subtract(
|
||||
summaryData.totalAdditionalCost
|
||||
);
|
||||
summaryData.totalAdditionalGppercent = (
|
||||
(summaryData.totalAdditionalGp.getAmount() /
|
||||
summaryData.totalAdditionalSales.getAmount()) *
|
||||
100
|
||||
).toFixed(2);
|
||||
summaryData.totalAdditionalGppercentFormatted = formatGpPercent(
|
||||
summaryData.totalAdditionalGppercent
|
||||
);
|
||||
|
||||
summaryData.gpdollars = summaryData.totalSales.subtract(
|
||||
summaryData.totalCost
|
||||
|
||||
38
server/tasks/tasks.js
Normal file
38
server/tasks/tasks.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
const axios = require("axios");
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const emailer = require("../email/sendemail");
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
exports.taskHandler = async (req, res) => {
|
||||
try {
|
||||
const { bodyshopid, query, variables, text, to, subject } = req.body;
|
||||
//Run the query
|
||||
const response = await client.request(query, variables);
|
||||
//Massage the data
|
||||
//Send the email
|
||||
const rootElement = response[Object.keys(response)[0]]; //This element shoudl always be an array.
|
||||
let converter = require("json-2-csv");
|
||||
converter.json2csv(rootElement, (err, csv) => {
|
||||
if (err) {
|
||||
res.status(500).json(err);
|
||||
}
|
||||
|
||||
emailer.sendTaskEmail({
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
attachments: [{ filename: "query.csv", content: csv }],
|
||||
});
|
||||
res.status(200).send(csv);
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user