From 1ae2133d230291f78479af7335dc9dbb1afd0811 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 5 Mar 2024 08:41:52 -0500 Subject: [PATCH] ProManager WIP. --- .../error-boundary.component.jsx | 2 +- .../job-detail-lines/job-lines.component.jsx | 1244 ++++++++--------- .../jobs-available-table.container.jsx | 45 +- client/src/redux/user/user.sagas.js | 2 +- client/src/utils/instanceRenderMgr.js | 13 +- server/firebase/firebase-handler.js | 2 +- server/job/job-totals-USA.js | 8 +- server/job/job-totals.js | 2 +- server/job/job.js | 21 +- server/utils/instanceMgr.js | 58 +- 10 files changed, 707 insertions(+), 690 deletions(-) diff --git a/client/src/components/error-boundary/error-boundary.component.jsx b/client/src/components/error-boundary/error-boundary.component.jsx index a14474854..d12926cf6 100644 --- a/client/src/components/error-boundary/error-boundary.component.jsx +++ b/client/src/components/error-boundary/error-boundary.component.jsx @@ -38,7 +38,7 @@ class ErrorBoundary extends React.Component { } handleErrorSubmit = () => { - InstanceRenderManager({executeFunction:true, imex: () => { + InstanceRenderManager({executeFunction:true,args:[], imex: () => { window.$crisp.push([ "do", "message:send", diff --git a/client/src/components/job-detail-lines/job-lines.component.jsx b/client/src/components/job-detail-lines/job-lines.component.jsx index a64771a86..4ec5c4bab 100644 --- a/client/src/components/job-detail-lines/job-lines.component.jsx +++ b/client/src/components/job-detail-lines/job-lines.component.jsx @@ -1,677 +1,639 @@ import { - DeleteFilled, - EditFilled, - FilterFilled, - HomeOutlined, - MinusCircleTwoTone, - PlusCircleTwoTone, - SyncOutlined, - WarningFilled, -} from "@ant-design/icons"; -import {useMutation} from "@apollo/client"; -import {Button, Dropdown, Input, Space, Table, Tag,} from "antd"; -import {PageHeader} from "@ant-design/pro-layout"; -import axios from "axios"; -import React, {useState} from "react"; -import {useTranslation} from "react-i18next"; -import {connect} from "react-redux"; -import {createStructuredSelector} from "reselect"; -import {DELETE_JOB_LINE_BY_PK} from "../../graphql/jobs-lines.queries"; -import {selectJobReadOnly} from "../../redux/application/application.selectors"; -import {setModalContext} from "../../redux/modals/modals.actions"; -import {selectTechnician} from "../../redux/tech/tech.selectors"; -import {onlyUnique} from "../../utils/arrayHelper"; -import {alphaSort} from "../../utils/sorters"; -import JobLineLocationPopup from "../job-line-location-popup/job-line-location-popup.component"; -import JobLineNotePopup from "../job-line-note-popup/job-line-note-popup.component"; -import JobLineStatusPopup from "../job-line-status-popup/job-line-status-popup.component"; -import JobLinesBillRefernece from "../job-lines-bill-reference/job-lines-bill-reference.component"; + DeleteFilled, + EditFilled, + FilterFilled, + HomeOutlined, + MinusCircleTwoTone, + PlusCircleTwoTone, + SyncOutlined, + WarningFilled, +} from '@ant-design/icons'; +import { useMutation } from '@apollo/client'; +import { Button, Checkbox, Dropdown, Input, Space, Table, Tag } from 'antd'; +import { PageHeader } from '@ant-design/pro-layout'; +import axios from 'axios'; +import React, { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { connect } from 'react-redux'; +import { createStructuredSelector } from 'reselect'; +import { DELETE_JOB_LINE_BY_PK } from '../../graphql/jobs-lines.queries'; +import { selectJobReadOnly } from '../../redux/application/application.selectors'; +import { setModalContext } from '../../redux/modals/modals.actions'; +import { selectTechnician } from '../../redux/tech/tech.selectors'; +import { onlyUnique } from '../../utils/arrayHelper'; +import { alphaSort } from '../../utils/sorters'; +import JobLineLocationPopup from '../job-line-location-popup/job-line-location-popup.component'; +import JobLineNotePopup from '../job-line-note-popup/job-line-note-popup.component'; +import JobLineStatusPopup from '../job-line-status-popup/job-line-status-popup.component'; +import JobLinesBillRefernece from '../job-lines-bill-reference/job-lines-bill-reference.component'; // import AllocationsAssignmentContainer from "../allocations-assignment/allocations-assignment.container"; // import AllocationsBulkAssignmentContainer from "../allocations-bulk-assignment/allocations-bulk-assignment.container"; // import AllocationsEmployeeLabelContainer from "../allocations-employee-label/allocations-employee-label.container"; -import _ from "lodash"; -import JobCreateIOU from "../job-create-iou/job-create-iou.component"; -import JobSendPartPriceChangeComponent from "../job-send-parts-price-change/job-send-parts-price-change.component"; -import PartsOrderModalContainer from "../parts-order-modal/parts-order-modal.container"; -import JobLinesExpander from "./job-lines-expander.component"; -import {selectBodyshop} from "../../redux/user/user.selectors"; -import dayjs from "../../utils/day"; -import JobLinesPartPriceChange from "./job-lines-part-price-change.component"; -import JoblineTeamAssignment from "../job-line-team-assignment/job-line-team-assignmnent.component"; -import JobLineDispatchButton from "../job-line-dispatch-button/job-line-dispatch-button.component"; -import JobLineBulkAssignComponent from "../job-line-bulk-assign/job-line-bulk-assign.component"; -import {useSplitTreatments} from "@splitsoftware/splitio-react"; -import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component"; +import _ from 'lodash'; +import JobCreateIOU from '../job-create-iou/job-create-iou.component'; +import JobSendPartPriceChangeComponent from '../job-send-parts-price-change/job-send-parts-price-change.component'; +import PartsOrderModalContainer from '../parts-order-modal/parts-order-modal.container'; +import JobLinesExpander from './job-lines-expander.component'; +import { selectBodyshop } from '../../redux/user/user.selectors'; +import dayjs from '../../utils/day'; +import JobLinesPartPriceChange from './job-lines-part-price-change.component'; +import JoblineTeamAssignment from '../job-line-team-assignment/job-line-team-assignmnent.component'; +import JobLineDispatchButton from '../job-line-dispatch-button/job-line-dispatch-button.component'; +import JobLineBulkAssignComponent from '../job-line-bulk-assign/job-line-bulk-assign.component'; +import { useSplitTreatments } from '@splitsoftware/splitio-react'; +import { HasFeatureAccess } from '../feature-wrapper/feature-wrapper.component'; const mapStateToProps = createStructuredSelector({ - bodyshop: selectBodyshop, - jobRO: selectJobReadOnly, - technician: selectTechnician, + bodyshop: selectBodyshop, + jobRO: selectJobReadOnly, + technician: selectTechnician, }); const mapDispatchToProps = (dispatch) => ({ - setJobLineEditContext: (context) => - dispatch(setModalContext({context: context, modal: "jobLineEdit"})), - setPartsOrderContext: (context) => - dispatch(setModalContext({context: context, modal: "partsOrder"})), - setBillEnterContext: (context) => - dispatch(setModalContext({context: context, modal: "billEnter"})), + setJobLineEditContext: (context) => + dispatch(setModalContext({ context: context, modal: 'jobLineEdit' })), + setPartsOrderContext: (context) => + dispatch(setModalContext({ context: context, modal: 'partsOrder' })), + setBillEnterContext: (context) => + dispatch(setModalContext({ context: context, modal: 'billEnter' })), }); export function JobLinesComponent({ - bodyshop, - jobRO, - technician, - setPartsOrderContext, - loading, - refetch, - jobLines, - setSearchText, - job, - setJobLineEditContext, - form, - setBillEnterContext, - }) { - const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK); - const {treatments: {Enhanced_Payroll}} = useSplitTreatments({ - attributes: {}, - names: ["Enhanced_Payroll"], - splitKey: bodyshop.imexshopid, - }); + bodyshop, + jobRO, + technician, + setPartsOrderContext, + loading, + refetch, + jobLines, + setSearchText, + job, + setJobLineEditContext, + form, + setBillEnterContext, +}) { + const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK); + const { + treatments: { Enhanced_Payroll }, + } = useSplitTreatments({ + attributes: {}, + names: ['Enhanced_Payroll'], + splitKey: bodyshop.imexshopid, + }); - const [selectedLines, setSelectedLines] = useState([]); - const [state, setState] = useState({ - sortedInfo: {}, - filteredInfo: {}, - }); - const {t} = useTranslation(); - const jobIsPrivate = bodyshop.md_ins_cos.find( - (c) => c.name === job.ins_co_nm - )?.private; + const [selectedLines, setSelectedLines] = useState([]); + const [state, setState] = useState({ + sortedInfo: {}, + filteredInfo: {}, + }); + const { t } = useTranslation(); + const jobIsPrivate = bodyshop.md_ins_cos.find((c) => c.name === job.ins_co_nm)?.private; - const columns = [ - { - title: "#", - dataIndex: "line_no", - key: "line_no", - sorter: (a, b) => a.line_no - b.line_no, - fixed: "left", - sortOrder: - state.sortedInfo.columnKey === "line_no" && state.sortedInfo.order, + const columns = [ + { + title: '#', + dataIndex: 'line_no', + key: 'line_no', + sorter: (a, b) => a.line_no - b.line_no, + fixed: 'left', + sortOrder: state.sortedInfo.columnKey === 'line_no' && state.sortedInfo.order, + }, + { + title: t('joblines.fields.line_desc'), + dataIndex: 'line_desc', + fixed: 'left', + key: 'line_desc', + sorter: (a, b) => alphaSort(a.line_desc, b.line_desc), + onCell: (record) => ({ + className: record.manual_line && 'job-line-manual', + style: { + ...(record.critical ? { boxShadow: ' -.5em 0 0 #FFC107' } : {}), }, - { - title: t("joblines.fields.line_desc"), - dataIndex: "line_desc", - fixed: "left", - key: "line_desc", - sorter: (a, b) => alphaSort(a.line_desc, b.line_desc), - onCell: (record) => ({ - className: record.manual_line && "job-line-manual", - style: { - ...(record.critical ? {boxShadow: " -.5em 0 0 #FFC107"} : {}), - }, - }), - sortOrder: - state.sortedInfo.columnKey === "line_desc" && state.sortedInfo.order, - ellipsis: true, + }), + sortOrder: state.sortedInfo.columnKey === 'line_desc' && state.sortedInfo.order, + ellipsis: true, + }, + { + title: t('joblines.fields.oem_partno'), + dataIndex: 'oem_partno', + key: 'oem_partno', + sorter: (a, b) => alphaSort(a.oem_partno, b.oem_partno), + sortOrder: state.sortedInfo.columnKey === 'oem_partno' && state.sortedInfo.order, + ellipsis: true, + onCell: (record) => ({ + className: record.manual_line && 'job-line-manual', + style: { + ...(record.parts_dispatch_lines[0]?.accepted_at + ? { boxShadow: ' -.5em 0 0 #FFC107' } + : {}), }, - { - title: t("joblines.fields.oem_partno"), - dataIndex: "oem_partno", - key: "oem_partno", - sorter: (a, b) => alphaSort(a.oem_partno, b.oem_partno), - sortOrder: - state.sortedInfo.columnKey === "oem_partno" && state.sortedInfo.order, - ellipsis: true, - onCell: (record) => ({ - className: record.manual_line && "job-line-manual", - style: { - ...(record.parts_dispatch_lines[0]?.accepted_at - ? {boxShadow: " -.5em 0 0 #FFC107"} - : {}), - }, - }), - render: (text, record) => ( - - {`${record.oem_partno || ""} ${ - record.alt_partno ? `(${record.alt_partno})` : "" - }`.trim()} + }), + render: (text, record) => ( + + {`${record.oem_partno || ''} ${record.alt_partno ? `(${record.alt_partno})` : ''}`.trim()} - ), + ), + }, + { + title: t('joblines.fields.op_code_desc'), + dataIndex: 'op_code_desc', + key: 'op_code_desc', + sorter: (a, b) => alphaSort(a.op_code_desc, b.op_code_desc), + sortOrder: state.sortedInfo.columnKey === 'op_code_desc' && state.sortedInfo.order, + ellipsis: true, + render: (text, record) => + `${record.op_code_desc || ''}${record.alt_partm ? ` ${record.alt_partm}` : ''}`, + }, + { + title: t('joblines.fields.part_type'), + dataIndex: 'part_type', + key: 'part_type', + filteredValue: state.filteredInfo.part_type || null, + sorter: (a, b) => alphaSort(a.part_type, b.part_type), + sortOrder: state.sortedInfo.columnKey === 'part_type' && state.sortedInfo.order, + filters: [ + { + text: t('jobs.labels.partsfilter'), + value: ['PAN', 'PAC', 'PAR', 'PAL', 'PAA', 'PAM', 'PAP', 'PAS', 'PASL', 'PAG'], }, { - title: t("joblines.fields.op_code_desc"), - dataIndex: "op_code_desc", - key: "op_code_desc", - sorter: (a, b) => alphaSort(a.op_code_desc, b.op_code_desc), - sortOrder: - state.sortedInfo.columnKey === "op_code_desc" && state.sortedInfo.order, - ellipsis: true, - render: (text, record) => - `${record.op_code_desc || ""}${ - record.alt_partm ? ` ${record.alt_partm}` : "" - }`, + text: t('joblines.fields.part_types.PAN'), + value: ['PAN'], }, { - title: t("joblines.fields.part_type"), - dataIndex: "part_type", - key: "part_type", - filteredValue: state.filteredInfo.part_type || null, - sorter: (a, b) => alphaSort(a.part_type, b.part_type), - sortOrder: - state.sortedInfo.columnKey === "part_type" && state.sortedInfo.order, - filters: [ - { - text: t("jobs.labels.partsfilter"), - value: [ - "PAN", - "PAC", - "PAR", - "PAL", - "PAA", - "PAM", - "PAP", - "PAS", - "PASL", - "PAG", - ], - }, - { - text: t("joblines.fields.part_types.PAN"), - value: ["PAN"], - }, - { - text: t("joblines.fields.part_types.PAP"), - value: ["PAP"], - }, - { - text: t("joblines.fields.part_types.PAL"), - value: ["PAL"], - }, - { - text: t("joblines.fields.part_types.PAA"), - value: ["PAA"], - }, - { - text: t("joblines.fields.part_types.PAG"), - value: ["PAG"], - }, - { - text: t("joblines.fields.part_types.PAS"), - value: ["PAS"], - }, - { - text: t("joblines.fields.part_types.PASL"), - value: ["PASL"], - }, - { - text: t("joblines.fields.part_types.PAC"), - value: ["PAC"], - }, - { - text: t("joblines.fields.part_types.PAR"), - value: ["PAR"], - }, - { - text: t("joblines.fields.part_types.PAM"), - value: ["PAM"], - }, - ], - onFilter: (value, record) => value.includes(record.part_type), - render: (text, record) => - record.part_type - ? t(`joblines.fields.part_types.${record.part_type}`) - : null, + text: t('joblines.fields.part_types.PAP'), + value: ['PAP'], }, + { + text: t('joblines.fields.part_types.PAL'), + value: ['PAL'], + }, + { + text: t('joblines.fields.part_types.PAA'), + value: ['PAA'], + }, + { + text: t('joblines.fields.part_types.PAG'), + value: ['PAG'], + }, + { + text: t('joblines.fields.part_types.PAS'), + value: ['PAS'], + }, + { + text: t('joblines.fields.part_types.PASL'), + value: ['PASL'], + }, + { + text: t('joblines.fields.part_types.PAC'), + value: ['PAC'], + }, + { + text: t('joblines.fields.part_types.PAR'), + value: ['PAR'], + }, + { + text: t('joblines.fields.part_types.PAM'), + value: ['PAM'], + }, + ], + onFilter: (value, record) => value.includes(record.part_type), + render: (text, record) => + record.part_type ? t(`joblines.fields.part_types.${record.part_type}`) : null, + }, - { - title: t("joblines.fields.act_price"), - dataIndex: "act_price", - key: "act_price", - sorter: (a, b) => a.act_price - b.act_price, - sortOrder: - state.sortedInfo.columnKey === "act_price" && state.sortedInfo.order, - ellipsis: true, + { + title: t('joblines.fields.act_price'), + dataIndex: 'act_price', + key: 'act_price', + sorter: (a, b) => a.act_price - b.act_price, + sortOrder: state.sortedInfo.columnKey === 'act_price' && state.sortedInfo.order, + ellipsis: true, + render: (text, record) => ( + + ), + }, + { + title: t('joblines.fields.part_qty'), + dataIndex: 'part_qty', + key: 'part_qty', + }, + + { + title: t('joblines.fields.tax_part'), + dataIndex: 'tax_part', + key: 'tax_part', + render: (text, record) => , + }, + // { + // title: t("joblines.fields.total"), + // dataIndex: "total", + // key: "total", + // sorter: (a, b) => a.act_price * a.part_qty - b.act_price * b.part_qty, + // sortOrder: + // state.sortedInfo.columnKey === "total" && state.sortedInfo.order, + // ellipsis: true, + // render: (text, record) => ( + // + // {record.act_price * record.part_qty} + // + // ), + // }, + { + title: t('joblines.fields.mod_lbr_ty'), + dataIndex: 'mod_lbr_ty', + key: 'mod_lbr_ty', + + sorter: (a, b) => alphaSort(a.mod_lbr_ty, b.mod_lbr_ty), + sortOrder: state.sortedInfo.columnKey === 'mod_lbr_ty' && state.sortedInfo.order, + render: (text, record) => + record.mod_lbr_ty ? t(`joblines.fields.lbr_types.${record.mod_lbr_ty}`) : null, + }, + { + title: t('joblines.fields.mod_lb_hrs'), + dataIndex: 'mod_lb_hrs', + key: 'mod_lb_hrs', + + sorter: (a, b) => a.mod_lb_hrs - b.mod_lb_hrs, + sortOrder: state.sortedInfo.columnKey === 'mod_lb_hrs' && state.sortedInfo.order, + }, + { + title: t('joblines.fields.line_ind'), + dataIndex: 'line_ind', + key: 'line_ind', + sorter: (a, b) => alphaSort(a.line_ind, b.line_ind), + sortOrder: state.sortedInfo.columnKey === 'line_ind' && state.sortedInfo.order, + responsive: ['md'], + }, + ...(Enhanced_Payroll.treatment === 'on' + ? [ + { + title: t('joblines.fields.assigned_team'), + dataIndex: 'assigned_team', + key: 'assigned_team', render: (text, record) => ( - + ), - }, - { - title: t("joblines.fields.part_qty"), - dataIndex: "part_qty", - key: "part_qty", - }, - // { - // title: t("joblines.fields.total"), - // dataIndex: "total", - // key: "total", - // sorter: (a, b) => a.act_price * a.part_qty - b.act_price * b.part_qty, - // sortOrder: - // state.sortedInfo.columnKey === "total" && state.sortedInfo.order, - // ellipsis: true, - // render: (text, record) => ( - // - // {record.act_price * record.part_qty} - // - // ), - // }, - { - title: t("joblines.fields.mod_lbr_ty"), - dataIndex: "mod_lbr_ty", - key: "mod_lbr_ty", - - sorter: (a, b) => alphaSort(a.mod_lbr_ty, b.mod_lbr_ty), - sortOrder: - state.sortedInfo.columnKey === "mod_lbr_ty" && state.sortedInfo.order, - render: (text, record) => - record.mod_lbr_ty - ? t(`joblines.fields.lbr_types.${record.mod_lbr_ty}`) - : null, - }, - { - title: t("joblines.fields.mod_lb_hrs"), - dataIndex: "mod_lb_hrs", - key: "mod_lb_hrs", - - sorter: (a, b) => a.mod_lb_hrs - b.mod_lb_hrs, - sortOrder: - state.sortedInfo.columnKey === "mod_lb_hrs" && state.sortedInfo.order, - }, - { - title: t("joblines.fields.line_ind"), - dataIndex: "line_ind", - key: "line_ind", - sorter: (a, b) => alphaSort(a.line_ind, b.line_ind), - sortOrder: - state.sortedInfo.columnKey === "line_ind" && state.sortedInfo.order, - responsive: ["md"], - }, - ...(Enhanced_Payroll.treatment === "on" - ? [ - { - title: t("joblines.fields.assigned_team"), - dataIndex: "assigned_team", - key: "assigned_team", - render: (text, record) => ( - - ), - }, - ] - : []), - - { - title: t("joblines.fields.notes"), - dataIndex: "notes", - key: "notes", - render: (text, record) => ( - - ), - }, - { - title: t("joblines.fields.location"), - dataIndex: "location", - key: "location", - render: (text, record) => ( - - ), - }, - ...HasFeatureAccess({featureName: "bills"}) ? [ { - title: t("joblines.labels.billref"), - dataIndex: "billref", - key: "billref", - render: (text, record) => , - responsive: ["md"], - },] : [], - { - title: t("joblines.fields.status"), - dataIndex: "status", - key: "status", - sorter: (a, b) => alphaSort(a.status, b.status), - sortOrder: - state.sortedInfo.columnKey === "status" && state.sortedInfo.order, - filteredValue: state.filteredInfo.status || null, - - filters: - (jobLines && - jobLines - .map((l) => l.status) - .filter(onlyUnique) - .map((s) => { - return { - text: s || "No Status*", - value: [s], - }; - })) || - [], - onFilter: (value, record) => value.includes(record.status), - render: (text, record) => ( - - ), - }, - { - title: t("general.labels.actions"), - dataIndex: "actions", - key: "actions", - render: (text, record) => ( - - {(record.manual_line || jobIsPrivate) && ( - <> - - - - )} - - ), - }, - ]; - - const handleTableChange = (pagination, filters, sorter) => { - setState((state) => ({ - ...state, - filteredInfo: filters, - sortedInfo: sorter, - })); - }; - - const handleMark = (e) => { - if (e.key === "clear") { - setSelectedLines([]); - } else { - const markedTypes = [e.key]; - if (e.key === "PAN") markedTypes.push("PAP"); - if (e.key === "PAS") markedTypes.push("PASL"); - setSelectedLines((selectedLines) => - _.uniq([ - ...selectedLines, - ...jobLines.filter( - (item) => - markedTypes.includes(item.part_type) || - markedTypes.includes(item.mod_lbr_ty) - ), - ]) - ); - } - }; - - const markMenu = { - onClick: handleMark, - items: [ - {key: "PAA", label: t("joblines.fields.part_types.PAA")}, - {key: "PAN", label: t("joblines.fields.part_types.PAN")}, - {key: "PAL", label: t("joblines.fields.part_types.PAL")}, - {key: "PAS", label: t("joblines.fields.part_types.PAS")}, - {type: 'divider'}, - {key: "LAA", label: t("joblines.fields.lbr_types.LAA")}, - {key: "LAB", label: t("joblines.fields.lbr_types.LAB")}, - {key: "LAD", label: t("joblines.fields.lbr_types.LAD")}, - {key: "LAE", label: t("joblines.fields.lbr_types.LAE")}, - {key: "LAF", label: t("joblines.fields.lbr_types.LAF")}, - {key: "LAG", label: t("joblines.fields.lbr_types.LAG")}, - {key: "LAM", label: t("joblines.fields.lbr_types.LAM")}, - {key: "LAR", label: t("joblines.fields.lbr_types.LAR")}, - {key: "LAS", label: t("joblines.fields.lbr_types.LAS")}, - {key: "LAU", label: t("joblines.fields.lbr_types.LAU")}, - {key: "LA1", label: t("joblines.fields.lbr_types.LA1")}, - {key: "LA2", label: t("joblines.fields.lbr_types.LA2")}, - {key: "LA3", label: t("joblines.fields.lbr_types.LA3")}, - {key: "LA4", label: t("joblines.fields.lbr_types.LA4")}, - {type: 'divider'}, - {key: "clear", label: t("general.labels.clear")}, + }, ] - }; + : []), - return ( -
- - - + { + title: t('joblines.fields.notes'), + dataIndex: 'notes', + key: 'notes', + render: (text, record) => , + }, + { + title: t('joblines.fields.location'), + dataIndex: 'location', + key: 'location', + render: (text, record) => , + }, + ...(HasFeatureAccess({ featureName: 'bills' }) + ? [ + { + title: t('joblines.labels.billref'), + dataIndex: 'billref', + key: 'billref', + render: (text, record) => , + responsive: ['md'], + }, + ] + : []), + { + title: t('joblines.fields.status'), + dataIndex: 'status', + key: 'status', + sorter: (a, b) => alphaSort(a.status, b.status), + sortOrder: state.sortedInfo.columnKey === 'status' && state.sortedInfo.order, + filteredValue: state.filteredInfo.status || null, - {job.special_coverage_policy && ( - - - - {t("jobs.labels.specialcoveragepolicy")} - - - )} - - {Enhanced_Payroll.treatment === "on" && ( - - )} - - - - - - - - {bodyshop.region_config.toLowerCase().startsWith("us") && ( - - )} - - { - e.preventDefault(); - setSearchText(e.target.value); - }} - /> - - } - /> - l.status) + .filter(onlyUnique) + .map((s) => { + return { + text: s || 'No Status*', + value: [s], + }; + })) || + [], + onFilter: (value, record) => value.includes(record.status), + render: (text, record) => , + }, + { + title: t('general.labels.actions'), + dataIndex: 'actions', + key: 'actions', + render: (text, record) => ( + + {(record.manual_line || jobIsPrivate) && ( + <> + + + + )} + + ), + }, + ]; + + const handleTableChange = (pagination, filters, sorter) => { + setState((state) => ({ + ...state, + filteredInfo: filters, + sortedInfo: sorter, + })); + }; + + const handleMark = (e) => { + if (e.key === 'clear') { + setSelectedLines([]); + } else { + const markedTypes = [e.key]; + if (e.key === 'PAN') markedTypes.push('PAP'); + if (e.key === 'PAS') markedTypes.push('PASL'); + setSelectedLines((selectedLines) => + _.uniq([ + ...selectedLines, + ...jobLines.filter( + (item) => markedTypes.includes(item.part_type) || markedTypes.includes(item.mod_lbr_ty) + ), + ]) + ); + } + }; + + const markMenu = { + onClick: handleMark, + items: [ + { key: 'PAA', label: t('joblines.fields.part_types.PAA') }, + { key: 'PAN', label: t('joblines.fields.part_types.PAN') }, + { key: 'PAL', label: t('joblines.fields.part_types.PAL') }, + { key: 'PAS', label: t('joblines.fields.part_types.PAS') }, + { type: 'divider' }, + { key: 'LAA', label: t('joblines.fields.lbr_types.LAA') }, + { key: 'LAB', label: t('joblines.fields.lbr_types.LAB') }, + { key: 'LAD', label: t('joblines.fields.lbr_types.LAD') }, + { key: 'LAE', label: t('joblines.fields.lbr_types.LAE') }, + { key: 'LAF', label: t('joblines.fields.lbr_types.LAF') }, + { key: 'LAG', label: t('joblines.fields.lbr_types.LAG') }, + { key: 'LAM', label: t('joblines.fields.lbr_types.LAM') }, + { key: 'LAR', label: t('joblines.fields.lbr_types.LAR') }, + { key: 'LAS', label: t('joblines.fields.lbr_types.LAS') }, + { key: 'LAU', label: t('joblines.fields.lbr_types.LAU') }, + { key: 'LA1', label: t('joblines.fields.lbr_types.LA1') }, + { key: 'LA2', label: t('joblines.fields.lbr_types.LA2') }, + { key: 'LA3', label: t('joblines.fields.lbr_types.LA3') }, + { key: 'LA4', label: t('joblines.fields.lbr_types.LA4') }, + { type: 'divider' }, + { key: 'clear', label: t('general.labels.clear') }, + ], + }; + + return ( +
+ + + + + {job.special_coverage_policy && ( + + + + {t('jobs.labels.specialcoveragepolicy')} + + + )} + -
- ); + {Enhanced_Payroll.treatment === 'on' && ( + + )} + + + + + + + + {bodyshop.region_config.toLowerCase().startsWith('us') && ( + + )} + + { + e.preventDefault(); + setSearchText(e.target.value); + }} + /> + + } + /> +
, + rowExpandable: (record) => true, + //expandRowByClick: true, + expandIcon: ({ expanded, onExpand, record }) => + expanded ? ( + onExpand(record, e)} /> + ) : ( + onExpand(record, e)} /> + ), + }} + onRow={(record, rowIndex) => { + return { + onDoubleClick: (event) => { + const notMatchingLines = selectedLines.filter((i) => i.id !== record.id); + notMatchingLines.length !== selectedLines.length + ? setSelectedLines(notMatchingLines) + : setSelectedLines([...selectedLines, record]); + }, // double click row + }; + }} + rowSelection={{ + selectedRowKeys: selectedLines.map((item) => item && item.id), + onSelectAll: (selected, selectedRows, changeRows) => { + setSelectedLines(selectedRows); + }, + onSelect: (record, selected, selectedRows, nativeEvent) => { + if (selected) { + setSelectedLines((selectedLines) => _.uniqBy([...selectedLines, record], 'id')); + } else { + setSelectedLines((selectedLines) => selectedLines.filter((l) => l.id !== record.id)); + } + }, + }} + /> + + ); } export default connect(mapStateToProps, mapDispatchToProps)(JobLinesComponent); diff --git a/client/src/components/jobs-available-table/jobs-available-table.container.jsx b/client/src/components/jobs-available-table/jobs-available-table.container.jsx index 21401c2ea..75b9ab4d0 100644 --- a/client/src/components/jobs-available-table/jobs-available-table.container.jsx +++ b/client/src/components/jobs-available-table/jobs-available-table.container.jsx @@ -111,12 +111,14 @@ export function JobsAvailableContainer({bodyshop, currentUser, insertAuditTrail, } // if (process.env.VITE_APP_COUNTRY === "USA") { //Massage the CCC file set to remove duplicate UNQ_SEQ. - InstanceRenderManager({executeFunction:true,rome: ResolveCCCLineIssues(estData.est_data, bodyshop) }) + InstanceRenderManager({executeFunction:true,rome: ResolveCCCLineIssues, args: [estData.est_data, bodyshop], promanager: ResolveCCCLineIssues }) // } else { //IO-539 Check for Parts Rate on PAL for SGI use case. //TODO:AIO Check that the async function is actually waiting before moving on. - InstanceRenderManager({executeFunction: true, imex: await CheckTaxRates(estData.est_data, bodyshop), rome: await CheckTaxRatesUSA(estData.est_data, bodyshop)}) + await InstanceRenderManager({executeFunction: true, + debug:true, + imex: CheckTaxRates, rome: CheckTaxRatesUSA, promanager: CheckTaxRatesUSA, args: [estData.est_data, bodyshop]}) // } // const newTotals = ( @@ -238,8 +240,8 @@ export function JobsAvailableContainer({bodyshop, currentUser, insertAuditTrail, let supp = replaceEmpty({...estData.est_data}); //IO-539 Check for Parts Rate on PAL for SGI use case. - InstanceRenderManager({executeFunction:true, imex: await CheckTaxRates(supp, bodyshop), rome: await CheckTaxRatesUSA(supp, bodyshop)}) - InstanceRenderManager({executeFunction:true ,rome: ResolveCCCLineIssues(supp, bodyshop) }) + await InstanceRenderManager({executeFunction:true, imex: CheckTaxRates, rome: CheckTaxRatesUSA, promanager: CheckTaxRatesUSA, args: [(supp, bodyshop)]}) + await InstanceRenderManager({executeFunction:true, rome: ResolveCCCLineIssues,promanager: ResolveCCCLineIssues ,args:[(supp, bodyshop)] }) delete supp.owner; delete supp.vehicle; @@ -599,7 +601,42 @@ async function CheckTaxRates(estData, bodyshop) { line.act_price = line.act_price + line.misc_amt; line.tax_part = !!line.misc_tax; } + //WEB EST SPECIFIC CLEAN UP + InstanceRenderManager({executeFunction: true, args:[], promanager: () => { + + if (line.mod_lbr_ty === "LAET" || line.mod_lbr_ty === "LAUT") { + line.notes += ` | ET/UT Update (prev = ${line.mod_lbr_ty})`; + line.mod_lbr_ty = "LAR"; + } + }}) }); + + //Group by line no + // For everything but the first one, strip out the price number in + + InstanceRenderManager({executeFunction:true, args:[], promanager: () => { + + + + const groupedByLineRef = _.groupBy(estData.joblines.data, "line_ref"); + Object.keys(groupedByLineRef).forEach((lineRef) => { + groupedByLineRef[lineRef].forEach((line, index) => { + //Let the first one keep it + if (index === 0) return; + //Web Est seems to have additional costs with UNQ_SEQ 0. Keep them all? + if (line.unq_seq === 0) return; + const indexInEstData = estData.joblines.data.findIndex( + (l) => l.unq_seq === line.unq_seq + ); + estData.joblines.data[ + indexInEstData + ].notes += ` | Scrubbed due to the line_ref issue. (prev act price = ${estData.joblines.data[indexInEstData].act_price})`; + estData.joblines.data[indexInEstData].act_price = 0; + estData.joblines.data[indexInEstData].db_price = 0; + }); + }) + }}) + //Generate the list of duplicated UNQ_SEQ that will feed into the next section to scrub the lines. const unqSeqHash = _.groupBy(estData.joblines.data, "unq_seq"); diff --git a/client/src/redux/user/user.sagas.js b/client/src/redux/user/user.sagas.js index 6b19ab2c6..ff35594c6 100644 --- a/client/src/redux/user/user.sagas.js +++ b/client/src/redux/user/user.sagas.js @@ -327,7 +327,7 @@ export function* SetAuthLevelFromShopDetails({payload}) { } try { - InstanceRenderManager({executeFunction:true, imex: () => { + InstanceRenderManager({executeFunction:true,args:[], imex: () => { window.$crisp.push(["set", "user:company", [payload.shopname]]); if (authRecord[0] && authRecord[0].user.validemail) { window.$crisp.push(["set", "user:email", [authRecord[0].user.email]]); diff --git a/client/src/utils/instanceRenderMgr.js b/client/src/utils/instanceRenderMgr.js index ea1be648c..92c77f4f9 100644 --- a/client/src/utils/instanceRenderMgr.js +++ b/client/src/utils/instanceRenderMgr.js @@ -16,6 +16,7 @@ export default function InstanceRenderManager({ imex, debug, instance, + args, }) { let propToReturn = null; @@ -38,17 +39,17 @@ export default function InstanceRenderManager({ break; } - if (executeFunction && typeof propToReturn === 'function') propToReturn(); - - //Checking to see if we need to default to another one. - if (propToReturn === 'imex') { - propToReturn = imex; - } if (debug) { console.log('InstanceRenderManager Debugger'); console.log('========================='); console.log({ executeFunction, rome, promanager, imex, debug, propToReturn }); console.log('========================='); } + + //Checking to see if we need to default to another one. + if (propToReturn === 'imex') { + propToReturn = imex; + } + if (executeFunction && typeof propToReturn === 'function') return propToReturn(...args); return propToReturn === undefined ? null : propToReturn; } diff --git a/server/firebase/firebase-handler.js b/server/firebase/firebase-handler.js index 049569881..7e7abb5b9 100644 --- a/server/firebase/firebase-handler.js +++ b/server/firebase/firebase-handler.js @@ -160,7 +160,7 @@ exports.sendNotification = async (req, res) => { .send({ topic: "PRD_PATRICK-messaging", notification: { - title: `ImEX Online Message - , + title: `ImEX Online Message - `, body: "Test Noti.", //imageUrl: "https://thinkimex.com/img/io-fcm.png", }, diff --git a/server/job/job-totals-USA.js b/server/job/job-totals-USA.js index 2e08d2e0a..f13ce3546 100644 --- a/server/job/job-totals-USA.js +++ b/server/job/job-totals-USA.js @@ -892,8 +892,8 @@ function CalculateTaxesTotals(job, otherTotals) { } }); - // console.log("*** Taxable Amounts***"); - // console.table(JSON.parse(JSON.stringify(taxableAmounts))); + console.log("*** Taxable Amounts***"); + console.table(JSON.parse(JSON.stringify(taxableAmounts))); //For the taxable amounts, figure out which tax type applies. //Then sum up the total of that tax type and then calculate the thresholds. @@ -976,8 +976,8 @@ function CalculateTaxesTotals(job, otherTotals) { }); const remainingTaxableAmounts = taxableAmountsByTier; - // console.log("*** Taxable Amounts by Tier***"); - // console.table(JSON.parse(JSON.stringify(taxableAmountsByTier))); + console.log("*** Taxable Amounts by Tier***"); + console.table(JSON.parse(JSON.stringify(taxableAmountsByTier))); Object.keys(taxableAmountsByTier).forEach((taxTierKey) => { try { diff --git a/server/job/job-totals.js b/server/job/job-totals.js index 9a2b0c1a6..cdfff6726 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -78,7 +78,7 @@ async function TotalsServerSide(req, res) { return ret; } catch (error) { - logger.log("job-totals-ssu-error", "ERROR", req.user.email, job.id, { + logger.log("job-totals-ssu-error", "ERROR", req?.user?.email, job.id, { jobid: job.id, error, }); diff --git a/server/job/job.js b/server/job/job.js index 7f968c0cd..a471baf13 100644 --- a/server/job/job.js +++ b/server/job/job.js @@ -1,11 +1,16 @@ -const RenderInstanceManager = require("../utils/instanceMgr").default; +const RenderInstanceManager = require('../utils/instanceMgr').default; exports.totals = RenderInstanceManager({ - imex: require("./job-totals").default, - rome: require("./job-totals-USA").default, + imex: require('./job-totals').default, + rome: require('./job-totals-USA').default, + promanager: require('./job-totals-USA').default, }); -exports.totalsSsu = require("./job-totals").totalsSsu; -exports.costing = require("./job-costing").JobCosting; -exports.costingmulti = require("./job-costing").JobCostingMulti; -exports.statustransition = require("./job-status-transition").statustransition; -exports.lifecycle = require("./job-lifecycle"); +exports.totalsSsu = RenderInstanceManager({ + imex: require('./job-totals').totalsSsu, + rome: require('./job-totals-USA').totalsSsu, + promanager: require('./job-totals-USA').totalsSsu, +}); +exports.costing = require('./job-costing').JobCosting; +exports.costingmulti = require('./job-costing').JobCostingMulti; +exports.statustransition = require('./job-status-transition').statustransition; +exports.lifecycle = require('./job-lifecycle'); diff --git a/server/utils/instanceMgr.js b/server/utils/instanceMgr.js index 3ac00e83c..9b25bb665 100644 --- a/server/utils/instanceMgr.js +++ b/server/utils/instanceMgr.js @@ -8,29 +8,41 @@ * @property { string | object | function } imex Return this prop if Rome. */ -function InstanceManager({ rome, promanager, imex }) { - let propToReturn = null; +function InstanceManager({ instance, debug, executeFunction, rome, promanager, imex }) { + let propToReturn = null; - switch (process.env.INSTANCE) { - case "IMEX": - propToReturn = imex; - break; - case "ROME": - propToReturn = rome; - break; - case "PROMANAGER": - propToReturn = promanager; - break; - default: - propToReturn = imex; - break; - } - // if (!propToReturn) { - // throw new Error( - // `Prop to return is not valid for this instance (${process.env.INSTANCE}).` - // ); - // } - return propToReturn; + switch (instance || process.env.INSTANCE) { + case 'IMEX': + propToReturn = imex; + break; + case 'ROME': + propToReturn = rome; //TODO:AIO Implement USE_IMEX + break; + case 'PROMANAGER': + //Return the rome prop if USE_ROME. + //If not USE_ROME, we want to default back to the rome prop if it's undefined. + //If null, we might want to show nothing, so make sure we return null. + propToReturn = + promanager === 'USE_ROME' ? rome : promanager !== undefined ? promanager : rome; + break; + default: + propToReturn = imex; + break; + } + + if (debug) { + console.log('InstanceRenderManager Debugger'); + console.log('========================='); + console.log({ executeFunction, rome, promanager, imex, debug, propToReturn }); + console.log('========================='); + } + + //Checking to see if we need to default to another one. + if (propToReturn === 'imex') { + propToReturn = imex; + } + if (executeFunction && typeof propToReturn === 'function') return propToReturn(...args); + return propToReturn === undefined ? null : propToReturn; } -exports.default = InstanceManager +exports.default = InstanceManager;