Compare commits
5 Commits
feature/IO
...
feature/IO
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eccc992cfa | ||
|
|
d187ed6f73 | ||
|
|
68c1ac3e70 | ||
|
|
2f267a9f2c | ||
|
|
d6fbf02092 |
@@ -1,6 +1,5 @@
|
||||
import { EditFilled } from "@ant-design/icons";
|
||||
import { Alert, Card, Col, Row, Space, Table, Typography } from "antd";
|
||||
import _ from "lodash";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
@@ -9,11 +8,11 @@ import { selectTechnician } from "../../redux/tech/tech.selectors";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
|
||||
import LaborAllocationsAdjustmentEdit from "../labor-allocations-adjustment-edit/labor-allocations-adjustment-edit.component";
|
||||
import UpsellComponent, { upsellEnum } from "../upsell/upsell.component";
|
||||
import "./labor-allocations-table.styles.scss";
|
||||
import { CalculateAllocationsTotals } from "./labor-allocations-table.utility";
|
||||
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
|
||||
import UpsellComponent, { upsellEnum } from "../upsell/upsell.component";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
technician: selectTechnician
|
||||
@@ -65,6 +64,7 @@ export function LaborAllocationsTable({
|
||||
key: "total",
|
||||
sorter: (a, b) => a.total - b.total,
|
||||
sortOrder: state.sortedInfo.columnKey === "total" && state.sortedInfo.order,
|
||||
align: "right",
|
||||
render: (text, record) => record.total.toFixed(1)
|
||||
},
|
||||
{
|
||||
@@ -73,6 +73,7 @@ export function LaborAllocationsTable({
|
||||
key: "hrs_claimed",
|
||||
sorter: (a, b) => a.claimed - b.claimed,
|
||||
sortOrder: state.sortedInfo.columnKey === "claimed" && state.sortedInfo.order,
|
||||
align: "right",
|
||||
render: (text, record) => record.claimed && record.claimed.toFixed(1)
|
||||
},
|
||||
{
|
||||
@@ -81,6 +82,7 @@ export function LaborAllocationsTable({
|
||||
key: "adjustments",
|
||||
sorter: (a, b) => a.adjustments - b.adjustments,
|
||||
sortOrder: state.sortedInfo.columnKey === "adjustments" && state.sortedInfo.order,
|
||||
align: "right",
|
||||
render: (text, record) => (
|
||||
<Space wrap>
|
||||
{record.adjustments.toFixed(1)}
|
||||
@@ -100,17 +102,17 @@ export function LaborAllocationsTable({
|
||||
{
|
||||
title: t("jobs.labels.difference"),
|
||||
dataIndex: "difference",
|
||||
|
||||
key: "difference",
|
||||
sorter: (a, b) => a.difference - b.difference,
|
||||
sortOrder: state.sortedInfo.columnKey === "difference" && state.sortedInfo.order,
|
||||
align: "right",
|
||||
render: (text, record) => (
|
||||
<strong
|
||||
style={{
|
||||
color: record.difference >= 0 ? "green" : "red"
|
||||
color: record.difference.toFixed(1) >= 0 ? "green" : "red"
|
||||
}}
|
||||
>
|
||||
{_.round(record.difference, 1)}
|
||||
{(Math.abs(record.difference) < 0.05 ? 0 : record.difference).toFixed(1)}
|
||||
</strong>
|
||||
)
|
||||
}
|
||||
@@ -129,7 +131,6 @@ export function LaborAllocationsTable({
|
||||
ellipsis: true,
|
||||
render: (text, record) => `${record.op_code_desc || ""}${record.alt_partm ? ` ${record.alt_partm}` : ""}`
|
||||
},
|
||||
|
||||
{
|
||||
title: t("joblines.fields.act_price"),
|
||||
dataIndex: "act_price",
|
||||
@@ -187,7 +188,7 @@ export function LaborAllocationsTable({
|
||||
{ hrs_total: 0, hrs_claimed: 0, adjustments: 0, difference: 0 }
|
||||
);
|
||||
|
||||
if (summary.difference !== 0 && typeof warningCallback === "function") {
|
||||
if (Math.abs(summary.difference.toFixed(1)) !== 0 && typeof warningCallback === "function") {
|
||||
warningCallback({ key: "labor", warning: t("jobs.labels.outstandinghours") });
|
||||
}
|
||||
|
||||
@@ -217,19 +218,21 @@ export function LaborAllocationsTable({
|
||||
summary={() => (
|
||||
<Table.Summary.Row>
|
||||
<Table.Summary.Cell>
|
||||
<Typography.Title level={4}>{t("general.labels.totals")}</Typography.Title>
|
||||
<Typography.Title level={4} style={{ margin: 0, lineHeight: 1 }}>
|
||||
{t("general.labels.totals")}
|
||||
</Typography.Title>
|
||||
</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{summary.hrs_total.toFixed(1)}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{summary.hrs_claimed.toFixed(1)}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>{summary.adjustments.toFixed(1)}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell>
|
||||
<Table.Summary.Cell align="right">{summary.hrs_total.toFixed(1)}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell align="right">{summary.hrs_claimed.toFixed(1)}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell align="right">{summary.adjustments.toFixed(1)}</Table.Summary.Cell>
|
||||
<Table.Summary.Cell align="right">
|
||||
<Typography.Text
|
||||
style={{
|
||||
fontWeight: "bold",
|
||||
color: summary.difference >= 0 ? "green" : "red"
|
||||
color: summary.difference.toFixed(1) >= 0 ? "green" : "red"
|
||||
}}
|
||||
>
|
||||
{summary.difference.toFixed(1)}
|
||||
{(Math.abs(summary.difference) < 0.05 ? 0 : summary.difference).toFixed(1)}
|
||||
</Typography.Text>
|
||||
</Table.Summary.Cell>
|
||||
</Table.Summary.Row>
|
||||
@@ -261,11 +264,10 @@ export function LaborAllocationsTable({
|
||||
</Card>
|
||||
</Col>
|
||||
)}
|
||||
{showWarning && summary.difference !== 0 && (
|
||||
{showWarning && Math.abs(summary.difference.toFixed(1)) !== 0 && (
|
||||
<Alert style={{ margin: "8px 0px" }} type="warning" message={t("jobs.labels.outstandinghours")} />
|
||||
)}
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(LaborAllocationsTable);
|
||||
|
||||
@@ -329,7 +329,8 @@ const main = async () => {
|
||||
main().catch((error) => {
|
||||
logger.log(`Main-API-Error: Something was not caught in the application.`, "error", "api", null, {
|
||||
error: error.message,
|
||||
errorjson: JSON.stringify(error)
|
||||
errorjson: JSON.stringify(error),
|
||||
stack: error.stack
|
||||
});
|
||||
// Note: If we want the app to crash on all uncaught async operations, we would
|
||||
// need to put a `process.exit(1);` here
|
||||
|
||||
@@ -3,3 +3,4 @@ exports.autohouse = require("./autohouse").default;
|
||||
exports.chatter = require("./chatter").default;
|
||||
exports.claimscorp = require("./claimscorp").default;
|
||||
exports.kaizen = require("./kaizen").default;
|
||||
exports.usageReport = require("./usageReport").default;
|
||||
90
server/data/usageReport.js
Normal file
90
server/data/usageReport.js
Normal file
@@ -0,0 +1,90 @@
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const emailer = require("../email/sendemail");
|
||||
const moment = require("moment-timezone");
|
||||
const converter = require("json-2-csv");
|
||||
const logger = require("../utils/logger");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const InstanceMgr = require("../utils/instanceMgr").default;
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
try {
|
||||
logger.log("usage-report-email-start", "debug", req?.user?.email, null, {});
|
||||
|
||||
if (InstanceMgr({ rome: false, imex: true })) {
|
||||
//Disable for ImEX at the moment.
|
||||
res.sendStatus(403);
|
||||
logger.log("usage-report-email-forbidden", "warn", req?.user?.email, null, {});
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
}
|
||||
// Validate using autohouse token header.
|
||||
if (req.headers["x-imex-auth"] !== process.env.AUTOHOUSE_AUTH_TOKEN) {
|
||||
res.sendStatus(401);
|
||||
logger.log("usage-report-email-forbidden", "warn", req?.user?.email, null, {});
|
||||
return;
|
||||
}
|
||||
|
||||
//Query the usage data.
|
||||
const queryResults = await client.request(queries.STATUS_UPDATE, {
|
||||
today: moment().startOf("day").subtract(3, "days"),
|
||||
period: moment().subtract(90, "days").startOf("day")
|
||||
});
|
||||
|
||||
//Massage the data.
|
||||
const shopList = queryResults.bodyshops.map((shop) => ({
|
||||
"Shop Name": shop.shopname,
|
||||
"Days Since Creation": moment().diff(moment(shop.created_at), "days"),
|
||||
"Jobs Created": shop.jobs_created.aggregate.count,
|
||||
"Jobs Updated": shop.jobs_updated.aggregate.count,
|
||||
"Owners Created": shop.owners_created.aggregate.count,
|
||||
"Owners Updated": shop.owners_updated.aggregate.count,
|
||||
"Vehicles Created": shop.vehicles_created.aggregate.count,
|
||||
"Vehicles Updated": shop.vehicles_updated.aggregate.count,
|
||||
"Tasks Created": shop.tasks_created.aggregate.count,
|
||||
"Tasks Updated": shop.tasks_updated.aggregate.count
|
||||
}));
|
||||
|
||||
const csv = converter.json2csv(shopList, { emptyFieldValue: "" });
|
||||
emailer
|
||||
.sendTaskEmail({
|
||||
to: ["patrick.fic@convenient-brands.com", "bradley.rhoades@convenient-brands.com"],
|
||||
subject: `RO Usage Report - ${moment().format("MM/DD/YYYY")}`,
|
||||
text: `
|
||||
Usage Report for ${moment().format("MM/DD/YYYY")} for Rome Online Customers.
|
||||
|
||||
Notes:
|
||||
- Days Since Creation: The number of days since the shop was created. Only shops created in the last 90 days are included.
|
||||
- Updated values should be higher than created values.
|
||||
- Counts are inclusive of the last 3 days of data.
|
||||
`,
|
||||
attachments: [{ filename: `RO Usage Report ${moment().format("MM/DD/YYYY")}.csv`, content: csv }]
|
||||
})
|
||||
.then(() => {
|
||||
logger.log("usage-report-email-success", "debug", req?.user?.email, null, {
|
||||
csv
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.log("usage-report-email-send-error", "ERROR", req?.user?.email, null, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
});
|
||||
res.sendStatus(200);
|
||||
return;
|
||||
} catch (error) {
|
||||
logger.log("usage-report-email-error", "ERROR", req?.user?.email, null, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
res.status(500).json({ error: error.message, stack: error.stack });
|
||||
}
|
||||
};
|
||||
@@ -2617,3 +2617,76 @@ exports.CREATE_CONVERSATION = `mutation CREATE_CONVERSATION($conversation: [conv
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
exports.STATUS_UPDATE = `query STATUS_UPDATE($period: timestamptz!, $today: timestamptz!) {
|
||||
bodyshops(where: { created_at: { _gte: $period } }) {
|
||||
shopname
|
||||
id
|
||||
created_at
|
||||
jobs_created: jobs_aggregate(where: { created_at: { _gte: $today } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
jobs_updated: jobs_aggregate(where: { updated_at: { _gte: $today } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
owners_created: owners_aggregate(where: { created_at: { _gte: $today } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
owners_updated: owners_aggregate(where: { updated_at: { _gte: $today } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
vehicles_created: vehicles_aggregate(
|
||||
where: { created_at: { _gte: $today } }
|
||||
) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
vehicles_updated: vehicles_aggregate(
|
||||
where: { updated_at: { _gte: $today } }
|
||||
) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
tasks_created: tasks_aggregate(where: { created_at: { _gte: $today } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
tasks_updated: tasks_aggregate(where: { updated_at: { _gte: $today } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
jobs {
|
||||
parts_orders_created: parts_orders_aggregate(
|
||||
where: { created_at: { _gte: $today } }
|
||||
) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
parts_orders_updated: parts_orders_aggregate(
|
||||
where: { updated_at: { _gte: $today } }
|
||||
) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -1,10 +1,11 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const { autohouse, claimscorp, chatter, kaizen } = require("../data/data");
|
||||
const { autohouse, claimscorp, chatter, kaizen, usageReport } = require("../data/data");
|
||||
|
||||
router.post("/ah", autohouse);
|
||||
router.post("/cc", claimscorp);
|
||||
router.post("/chatter", chatter);
|
||||
router.post("/kaizen", kaizen);
|
||||
router.post("/usagereport", usageReport);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -41,7 +41,7 @@ exports.taskHandler = async (req, res) => {
|
||||
|
||||
return res.status(200).send(csv);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message, stack: error.stackTrace });
|
||||
res.status(500).json({ error: error.message, stack: error.stack });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user