;
diff --git a/client/src/components/shop-template-editor-save-button/shop-template-editor-save-button.component.jsx b/client/src/components/shop-template-editor-save-button/shop-template-editor-save-button.component.jsx
index 692b19308..878c40305 100644
--- a/client/src/components/shop-template-editor-save-button/shop-template-editor-save-button.component.jsx
+++ b/client/src/components/shop-template-editor-save-button/shop-template-editor-save-button.component.jsx
@@ -22,11 +22,7 @@ export default function ShopTemplateSaveButton({
html: data.html,
url: `${window.location.protocol}://${window.location.host}/`,
});
- console.log(
- "🚀 ~ file: shop-template-editor-save-button.component.jsx ~ line 25 ~ emailEditorRef.current.exportHtml ~ inlineHtml",
- response
- );
-
+
const result = await updateTemplate({
variables: {
templateId: templateId,
diff --git a/client/src/debug.log b/client/src/debug.log
index a56efb4ec..6e8ec3bc1 100644
--- a/client/src/debug.log
+++ b/client/src/debug.log
@@ -2,3 +2,5 @@
[1008/114603.993:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[1008/121110.259:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
[1008/122424.146:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
+[0106/150233.556:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
+[0106/152014.936:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
diff --git a/client/src/graphql/bodyshop.queries.js b/client/src/graphql/bodyshop.queries.js
index 695d6885c..7ccf0b3fc 100644
--- a/client/src/graphql/bodyshop.queries.js
+++ b/client/src/graphql/bodyshop.queries.js
@@ -74,6 +74,7 @@ export const QUERY_BODYSHOP = gql`
appt_alt_transport
schedule_start_time
schedule_end_time
+ imexshopid
employees {
id
first_name
@@ -145,7 +146,8 @@ export const UPDATE_SHOP = gql`
appt_colors
appt_alt_transport
schedule_start_time
- schedule_end_time
+ schedule_end_time
+ imexshopid
employees {
id
first_name
diff --git a/client/src/utils/RenderTemplate.js b/client/src/utils/RenderTemplate.js
index 0f91bed13..49034bf89 100644
--- a/client/src/utils/RenderTemplate.js
+++ b/client/src/utils/RenderTemplate.js
@@ -1,43 +1,90 @@
-import axios from "axios";
import gql from "graphql-tag";
-import { QUERY_TEMPLATES_BY_NAME } from "../graphql/templates.queries";
+import jsreport from "jsreport-browser-client-dist";
import client from "../utils/GraphQLClient";
+import cleanAxios from "./CleanAxios";
-export default async function RenderTemplate(templateObject, bodyshop) {
- const { data: templateRecords } = await client.query({
- query: QUERY_TEMPLATES_BY_NAME,
- variables: { name: templateObject.name },
- fetchPolicy: "network-only",
- });
+const server = "https://reports.bodyshop.app";
+jsreport.serverUrl = server;
+jsreport.headers["Authorization"] = "Basic " + btoa("admin:admin");
- let templateToUse;
+export default async function RenderTemplate(
+ templateObject,
+ bodyshop,
+ renderAsHtml = false
+) {
+ //Template Object
+ // {
+ // name: TemplateList().parts_order_confirmation.key,
+ // variables: {
+ // id: insertResult.data.insert_parts_orders.returning[0].id,
+ // },
+ // },
- if (templateRecords.templates.length === 1) {
- console.log("[ITE] Using OOTB template.");
- templateToUse = templateRecords.templates[0];
- } else if (templateRecords.templates.length === 2) {
- console.log("[ITE] Found custom template.");
- templateToUse = templateRecords.templates.filter((t) => !!t.bodyshopid)[0];
- console.log("templateToUse", templateToUse);
+ //Query assets that match the template name. Must be in format <>.query
+ const jsReportQueries = await cleanAxios.get(
+ `${server}/odata/assets?$filter=name eq '${templateObject.name}.query'`,
+ { headers: { Authorization: "Basic " + btoa("admin:admin") } }
+ );
+
+ let templateQueryToExecute,
+ useShopSpecificTemplate = false;
+ if (jsReportQueries.data.value.length === 0) {
+ //We have no query to execute. Just render the template.
+ } else if (jsReportQueries.data.value.length === 1) {
+ //We're using the default template. Get the query and execute.
+ templateQueryToExecute = atob(jsReportQueries.data.value[0].content);
+ } else if (jsReportQueries.data.value.length === 2) {
+ //There's a custom template. Use that query instead and execute. We find it because it has a parent folder.
+ templateQueryToExecute = atob(
+ jsReportQueries.data.value.filter((v) => !!v.folder)[0].content
+ );
+ useShopSpecificTemplate = true;
} else {
- //No template found.Uh oh.
- alert("Error: Template key does not exist.");
- throw new Error("Template key does not exist.");
+ //We have too many queries to choose from. Throw an error.
+ alert(
+ "There are too many queries to choose from. Please ensure there are no conflicting keys."
+ );
+ throw new Error(
+ "There are too many queries to choose from. Please ensure there are no conflicting keys."
+ );
}
-
const { data: contextData } = await client.query({
- query: gql(templateToUse.query),
+ query: gql(templateQueryToExecute),
variables: { ...templateObject.variables },
fetchPolicy: "network-only",
});
- const { data } = await axios.post("/render", {
- view: templateToUse.html,
- context: { ...contextData, bodyshop: bodyshop },
- });
- return new Promise((resolve, reject) => {
- resolve(data);
- });
+ let reportRequest = {
+ template: {
+ name: useShopSpecificTemplate
+ ? `/${bodyshop.imexshopid}/${templateObject.name}`
+ : `/${templateObject.name}`,
+ ...(renderAsHtml ? {} : { recipe: "chrome-pdf" }),
+ },
+ data: {
+ ...contextData,
+ headerpath: `/${bodyshop.imexshopid}/header.html`,
+ bodyshop: bodyshop,
+ },
+ };
+ const render = await jsreport.renderAsync(reportRequest);
+
+ if (!renderAsHtml) {
+ render.download();
+ var html =
+ "" +
+ "" +
+ "" +
+ '' +
+ "";
+ displayTemplateInWindowNoprint(html);
+ } else {
+ return new Promise((resolve, reject) => {
+ resolve(render.toString());
+ });
+ }
}
export const displayTemplateInWindow = (html) => {
diff --git a/client/src/utils/TemplateConstants.js b/client/src/utils/TemplateConstants.js
index c410e92ff..e9bfd2bd3 100644
--- a/client/src/utils/TemplateConstants.js
+++ b/client/src/utils/TemplateConstants.js
@@ -14,97 +14,5 @@ export const TemplateList = (type, object) => {
drivingId: "job",
key: "estimate_detail",
},
- all_job_notes: {
- title: i18n.t("printcenter.jobs.all_job_notes"),
- description: "All jobs Notes including Private",
- drivingId: "job",
- key: "all_job_notes",
- },
- fippa_authorization: {
- title: i18n.t("printcenter.jobs.fippa_authorization"),
- description: "FIPPA Work Auth",
- drivingId: "job",
- key: "fippa_authorization",
- },
- casl_authorization: {
- title: i18n.t("printcenter.jobs.casl_authorization"),
- description: "CASL Auth",
- drivingId: "job",
- key: "casl_authorization",
- },
- window_tag: {
- title: i18n.t("printcenter.jobs.window_tag"),
- description: "Window Tag",
- drivingId: "job",
- key: "window_tag",
- },
- cover_sheet: {
- title: i18n.t("printcenter.jobs.cover_sheet"),
- description: "Cover Sheet",
- drivingId: "job",
- key: "cover_sheet",
- },
-
- time_tickets_by_employee: {
- title: "Time Tickets by Employee",
- description: "Time tickets for employee with date range",
- drivingId: "employee",
- key: "time_tickets_by_employee",
- },
-
- //Non Completed Items
- appointment_reminder: {
- title: "Appointment Reminder",
- description:
- "Sent to a customer as a reminder of an upcoming appointment.",
- drivingId: "appointment",
- key: "appointment_reminder",
- subject: `Appointment Reminder`,
- },
- appointment_confirmation: {
- title: "Appointment Confirmation",
- description:
- "Sent to a customer as a Confirmation of an upcoming appointment.",
- drivingId: "appointment",
- key: "appointment_confirmation",
- },
- parts_order_confirmation: {
- title: "Parts Order Confirmation",
- description: "Parts order template including part details",
- drivingId: "partsorder",
- key: "parts_order_confirmation",
- subject: `Parts Order for ${object}`,
- },
-
- cover_sheet_landscape: {
- title: "Cover Sheet - Landscape",
- description: "Cover sheet landscape",
- drivingId: "job",
- key: "cover_sheet_landscape",
- },
- cover_sheet_portrait: {
- title: "Cover Sheet - portrait",
- description: "Cover sheet portrait",
- drivingId: "job",
- key: "cover_sheet_portrait",
- },
- parts_return_confirmation: {
- title: "Parts Return Confirmation",
- description: "Parts Return template including part details",
- drivingId: "partsorder",
- key: "parts_return_confirmation",
- },
- csi_invitation: {
- title: "Customer Survey Invitation",
- description: "Customer Survey Invitation",
- drivingId: "csi",
- key: "csi_invitation",
- },
- payment_receipt: {
- title: "Payment Receipt",
- description: "Receipt of payment for customer",
- drivingId: "payment",
- key: "payment_receipt",
- },
};
};
diff --git a/client/templates/appointment_confirmation/appointment_confirmation.query.gql b/client/templates/appointment_confirmation/appointment_confirmation.query.gql
deleted file mode 100644
index 6e1c4f5a9..000000000
--- a/client/templates/appointment_confirmation/appointment_confirmation.query.gql
+++ /dev/null
@@ -1,11 +0,0 @@
-query EMAIL_APPOINTMENT_CONFIRMATION($id: uuid!) {
- appointments_by_pk(id: $id) {
- start
- title
- job {
- ownr_fn
- ownr_ln
- ownr_ea
- }
- }
-}
diff --git a/client/templates/appointment_confirmation/appointment_confirmation.template.html b/client/templates/appointment_confirmation/appointment_confirmation.template.html
deleted file mode 100644
index 5aa9669c7..000000000
--- a/client/templates/appointment_confirmation/appointment_confirmation.template.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
Hello {{appointments_by_pk.job.ownr_fn}},
-
- This is a confirmation that you have an appointment at
- {{appointments_by_pk.start}} to bring your car in for repair. Please email
- us at {{bodyshop.email}} if you can't make it.
-
- This is a reminder that you have an appointment at
- {{appointments_by_pk.start}} to bring your car in for repair. Please email
- us at {{bodyshop.email}} if you can't make it.
-
-
diff --git a/client/templates/csi_invitation/csi_invitation.query.gql b/client/templates/csi_invitation/csi_invitation.query.gql
deleted file mode 100644
index 0dacda99a..000000000
--- a/client/templates/csi_invitation/csi_invitation.query.gql
+++ /dev/null
@@ -1,6 +0,0 @@
-query ($id: uuid!){
- csi_by_pk(id: $id){
- id
- relateddata
- }
-}
\ No newline at end of file
diff --git a/client/templates/csi_invitation/csi_invitation.template.html b/client/templates/csi_invitation/csi_invitation.template.html
deleted file mode 100644
index ba8b22f31..000000000
--- a/client/templates/csi_invitation/csi_invitation.template.html
+++ /dev/null
@@ -1,45 +0,0 @@
-
Hi {{csi_by_pk.relateddata.job.ownr_fn}},
-
-
- Thank you for getting your car repaired at
- {{csi_by_pk.relateddata.bodyshop.shopname}}. We invite you to complete a
- survey about your experience.
-