From 7725080a113964abd86362d32ef5f7d0bf8540a9 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Thu, 20 Apr 2023 09:33:22 -0700 Subject: [PATCH] IO-2235 Exported GSR to Excel For Morrey Body Shop --- .../report-center-modal.component.jsx | 498 +++++++++--------- client/src/translations/en_us/common.json | 3 + client/src/translations/es/common.json | 3 + client/src/translations/fr/common.json | 3 + client/src/utils/TemplateConstants.js | 24 + 5 files changed, 296 insertions(+), 235 deletions(-) diff --git a/client/src/components/report-center-modal/report-center-modal.component.jsx b/client/src/components/report-center-modal/report-center-modal.component.jsx index e0db4f516..f2906c338 100644 --- a/client/src/components/report-center-modal/report-center-modal.component.jsx +++ b/client/src/components/report-center-modal/report-center-modal.component.jsx @@ -1,14 +1,14 @@ import { useLazyQuery } from "@apollo/client"; import { - Button, - Card, - Col, - DatePicker, - Form, - Input, - Radio, - Row, - Typography, + Button, + Card, + Col, + DatePicker, + Form, + Input, + Radio, + Row, + Typography, } from "antd"; import _ from "lodash"; import moment from "moment"; @@ -26,253 +26,281 @@ import EmployeeSearchSelect from "../employee-search-select/employee-search-sele import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component"; import "./report-center-modal.styles.scss"; const mapStateToProps = createStructuredSelector({ - reportCenterModal: selectReportCenter, + reportCenterModal: selectReportCenter, }); const mapDispatchToProps = (dispatch) => ({ - //setUserLanguage: language => dispatch(setUserLanguage(language)) + //setUserLanguage: language => dispatch(setUserLanguage(language)) }); export default connect( - mapStateToProps, - mapDispatchToProps + mapStateToProps, + mapDispatchToProps )(ReportCenterModalComponent); export function ReportCenterModalComponent({ reportCenterModal }) { - const [form] = Form.useForm(); - const [search, setSearch] = useState(""); + const [form] = Form.useForm(); + const [search, setSearch] = useState(""); - const [loading, setLoading] = useState(false); - const { t } = useTranslation(); - const Templates = TemplateList("report_center"); - const ReportsList = Object.keys(Templates).map((key) => { - return Templates[key]; - }); - const { visible } = reportCenterModal; + const [loading, setLoading] = useState(false); + const { t } = useTranslation(); + const Templates = TemplateList("report_center"); + const ReportsList = Object.keys(Templates).map((key) => { + return Templates[key]; + }); + const { visible } = reportCenterModal; - const [callVendorQuery, { data: vendorData, called: vendorCalled }] = - useLazyQuery(QUERY_ALL_VENDORS, { - skip: !( - visible && - Templates[form.getFieldValue("key")] && - Templates[form.getFieldValue("key")].idtype - ), - }); + const [callVendorQuery, { data: vendorData, called: vendorCalled }] = + useLazyQuery(QUERY_ALL_VENDORS, { + skip: !( + visible && + Templates[form.getFieldValue("key")] && + Templates[form.getFieldValue("key")].idtype + ), + }); - const [callEmployeeQuery, { data: employeeData, called: employeeCalled }] = - useLazyQuery(QUERY_ACTIVE_EMPLOYEES, { - skip: !( - visible && - Templates[form.getFieldValue("key")] && - Templates[form.getFieldValue("key")].idtype - ), - }); + const [callEmployeeQuery, { data: employeeData, called: employeeCalled }] = + useLazyQuery(QUERY_ACTIVE_EMPLOYEES, { + skip: !( + visible && + Templates[form.getFieldValue("key")] && + Templates[form.getFieldValue("key")].idtype + ), + }); - const handleFinish = async (values) => { - setLoading(true); - const start = values.dates[0]; - const end = values.dates[1]; - const { id } = values; + const handleFinish = async (values) => { + setLoading(true); + const start = values.dates[0]; + const end = values.dates[1]; + const { id } = values; - await GenerateDocument( - { - name: values.key, - variables: { - ...(start - ? { start: moment(start).startOf("day").format("YYYY-MM-DD") } - : {}), - ...(end - ? { end: moment(end).endOf("day").format("YYYY-MM-DD") } - : {}), - ...(start ? { starttz: moment(start).startOf("day") } : {}), - ...(end ? { endtz: moment(end).endOf("day") } : {}), + await GenerateDocument( + { + name: values.key, + variables: { + ...(start + ? { start: moment(start).startOf("day").format("YYYY-MM-DD") } + : {}), + ...(end + ? { end: moment(end).endOf("day").format("YYYY-MM-DD") } + : {}), + ...(start ? { starttz: moment(start).startOf("day") } : {}), + ...(end ? { endtz: moment(end).endOf("day") } : {}), - ...(id ? { id: id } : {}), - }, - }, - { - to: values.to, - subject: Templates[values.key]?.subject, - }, - values.sendby === "email" ? "e" : "p", - id - ); - setLoading(false); - }; + ...(id ? { id: id } : {}), + }, + }, + { + to: values.to, + subject: Templates[values.key]?.subject, + }, + values.sendby === "excel" ? "x" : values.sendby === "email" ? "e" : "p", + id + ); + setLoading(false); + }; - const FilteredReportsList = - search !== "" - ? ReportsList.filter((r) => - r.title.toLowerCase().includes(search.toLowerCase()) - ) - : ReportsList; + const FilteredReportsList = + search !== "" + ? ReportsList.filter((r) => + r.title.toLowerCase().includes(search.toLowerCase()) + ) + : ReportsList; - //Group it, create cards, and then filter out. + //Group it, create cards, and then filter out. - const grouped = _.groupBy(FilteredReportsList, "group"); + const grouped = _.groupBy(FilteredReportsList, "group"); - return ( -
-
- setSearch(e.target.value)} - value={search} - /> - - - {/* {Object.keys(Templates).map((key) => ( + return ( +
+ + setSearch(e.target.value)} + value={search} + /> + + + {/* {Object.keys(Templates).map((key) => ( {Templates[key].title} ))} */} - - {Object.keys(grouped).map((key) => ( - - - - {t(`reportcenter.labels.groups.${key}`)} - -
    - {grouped[key].map((item) => ( -
  • - - {item.title} - -
  • - ))} -
-
- - ))} -
-
-
- - {() => { - const key = form.getFieldValue("key"); - if (!key) return null; - //Kind of Id - const rangeFilter = Templates[key] && Templates[key].rangeFilter; - if (!rangeFilter) return null; - return ( -
- {t("reportcenter.labels.filterson", { - object: rangeFilter.object, - field: rangeFilter.field, - })} -
- ); - }} -
- - {() => { - const key = form.getFieldValue("key"); - const currentId = form.getFieldValue("id"); - if (!key) return null; - //Kind of Id - const idtype = Templates[key] && Templates[key].idtype; - if (!idtype && currentId) { - form.setFieldsValue({ id: null }); - return null; - } - if (!vendorCalled && idtype === "vendor") callVendorQuery(); - if (!employeeCalled && idtype === "employee") callEmployeeQuery(); - if (idtype === "vendor") - return ( - - - - ); - if (idtype === "employee") - return ( - - - - ); - else return null; - }} - - - - - - - {t("general.labels.email")} - {t("general.labels.print")} - - + + {Object.keys(grouped).map((key) => ( + + + + {t(`reportcenter.labels.groups.${key}`)} + +
    + {grouped[key].map((item) => ( +
  • + + {item.title} + +
  • + ))} +
+
+ + ))} +
+ + + + {() => { + const key = form.getFieldValue("key"); + if (!key) return null; + //Kind of Id + const rangeFilter = Templates[key] && Templates[key].rangeFilter; + if (!rangeFilter) return null; + return ( +
+ {t("reportcenter.labels.filterson", { + object: rangeFilter.object, + field: rangeFilter.field, + })} +
+ ); + }} +
+ + {() => { + const key = form.getFieldValue("key"); + const currentId = form.getFieldValue("id"); + if (!key) return null; + //Kind of Id + const idtype = Templates[key] && Templates[key].idtype; + if (!idtype && currentId) { + form.setFieldsValue({ id: null }); + return null; + } + if (!vendorCalled && idtype === "vendor") callVendorQuery(); + if (!employeeCalled && idtype === "employee") callEmployeeQuery(); + if (idtype === "vendor") + return ( + + + + ); + if (idtype === "employee") + return ( + + + + ); + else return null; + }} + + + + + + {() => { + const key = form.getFieldValue("key"); + const currentId = form.getFieldValue("id"); + if (!key) return null; + //Kind of Id + const idtype = Templates[key] && Templates[key].idtype; + if (!idtype && currentId) { + form.setFieldsValue({ id: null }); + return null; + } + if (idtype === "excel") + return ( + + + {t("general.labels.excel")} + + + ); + if (idtype !== "excel") + return ( + + + {t("general.labels.email")} + {t("general.labels.print")} + + + ); + }} + -
- -
- -
- ); +
+ +
+ +
+ ); } diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 725bf69e5..0249aba70 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1015,6 +1015,7 @@ "created_at": "Created At", "email": "Email", "errors": "Errors", + "excel": "Excel", "exceptiontitle": "An error has occurred.", "friday": "Friday", "globalsearch": "Global Search", @@ -2445,6 +2446,8 @@ "export_payables": "Export Log - Payables", "export_payments": "Export Log - Payments", "export_receivables": "Export Log - Receivables", + "exported_gsr_by_ro": "Exported Gross Sales - Excel", + "exported_gsr_by_ro_labor": "Exported Gross Sales (Labor) - Excel", "gsr_by_atp": "", "gsr_by_ats": "Gross Sales by ATS", "gsr_by_category": "Gross Sales by Category", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 0af8515dd..5d2ed6839 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1015,6 +1015,7 @@ "created_at": "", "email": "", "errors": "", + "excel": "", "exceptiontitle": "", "friday": "", "globalsearch": "", @@ -2445,6 +2446,8 @@ "export_payables": "", "export_payments": "", "export_receivables": "", + "exported_gsr_by_ro": "", + "exported_gsr_by_ro_labor": "", "gsr_by_atp": "", "gsr_by_ats": "", "gsr_by_category": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index c474c6c27..66c8ea469 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1015,6 +1015,7 @@ "created_at": "", "email": "", "errors": "", + "excel": "", "exceptiontitle": "", "friday": "", "globalsearch": "", @@ -2445,6 +2446,8 @@ "export_payables": "", "export_payments": "", "export_receivables": "", + "exported_gsr_by_ro": "", + "exported_gsr_by_ro_labor": "", "gsr_by_atp": "", "gsr_by_ats": "", "gsr_by_category": "", diff --git a/client/src/utils/TemplateConstants.js b/client/src/utils/TemplateConstants.js index e2aeb1132..ee36e687e 100644 --- a/client/src/utils/TemplateConstants.js +++ b/client/src/utils/TemplateConstants.js @@ -1857,6 +1857,30 @@ export const TemplateList = (type, context) => { }, group: "customers", }, + exported_gsr_by_ro: { + title: i18n.t("reportcenter.templates.exported_gsr_by_ro"), + subject: i18n.t("reportcenter.templates.exported_gsr_by_ro"), + key: "exported_gsr_by_ro", + idtype: "excel", + disabled: false, + rangeFilter: { + object: i18n.t("reportcenter.labels.objects.jobs"), + field: i18n.t("jobs.fields.date_exported"), + }, + group: "sales", + }, + exported_gsr_by_ro_labor: { + title: i18n.t("reportcenter.templates.exported_gsr_by_ro_labor"), + subject: i18n.t("reportcenter.templates.exported_gsr_by_ro_labor"), + key: "exported_gsr_by_ro_labor", + idtype: "excel", + disabled: false, + rangeFilter: { + object: i18n.t("reportcenter.labels.objects.jobs"), + field: i18n.t("jobs.fields.date_exported"), + }, + group: "sales", + }, } : {}), ...(!type || type === "courtesycarcontract"