- Merge client update into test-beta
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,78 +1,78 @@
|
||||
import { gql } from "@apollo/client";
|
||||
import {gql} from "@apollo/client";
|
||||
import _ from "lodash";
|
||||
import { GET_ALL_JOBLINES_BY_PK } from "../../graphql/jobs-lines.queries";
|
||||
import {GET_ALL_JOBLINES_BY_PK} from "../../graphql/jobs-lines.queries";
|
||||
|
||||
export const GetSupplementDelta = async (client, jobId, newLines) => {
|
||||
const {
|
||||
data: { joblines: existingLinesFromDb },
|
||||
} = await client.query({
|
||||
query: GET_ALL_JOBLINES_BY_PK,
|
||||
variables: { id: jobId },
|
||||
});
|
||||
|
||||
const existingLines = _.cloneDeep(existingLinesFromDb);
|
||||
const linesToInsert = [];
|
||||
const linesToUpdate = [];
|
||||
|
||||
newLines.forEach((newLine) => {
|
||||
const matchingIndex = existingLines.findIndex(
|
||||
(eL) => eL.unq_seq === newLine.unq_seq
|
||||
);
|
||||
|
||||
//Should do a check to make sure there is only 1 matching unq sequence number.
|
||||
|
||||
if (matchingIndex >= 0) {
|
||||
//Found a relevant matching line. Add it to lines to update.
|
||||
linesToUpdate.push({
|
||||
id: existingLines[matchingIndex].id,
|
||||
newData: { ...newLine, removed: false, act_price_before_ppc: null },
|
||||
});
|
||||
|
||||
//Splice out item we found for performance.
|
||||
existingLines.splice(matchingIndex, 1);
|
||||
} else {
|
||||
//Didn't find a match. Must be a new line.
|
||||
linesToInsert.push(newLine);
|
||||
}
|
||||
});
|
||||
|
||||
//Wahtever is left in the existing lines, are lines that should be removed.
|
||||
const insertQueries = linesToInsert.reduce((acc, value, idx) => {
|
||||
return acc + generateInsertQuery(value, idx, jobId);
|
||||
}, "");
|
||||
|
||||
const updateQueries = linesToUpdate.reduce((acc, value, idx) => {
|
||||
return acc + generateUpdateQuery(value, idx);
|
||||
}, "");
|
||||
|
||||
const removeQueries = existingLines
|
||||
.filter((l) => !l.manual_line)
|
||||
.reduce((acc, value, idx) => {
|
||||
return acc + generateRemoveQuery(value, idx);
|
||||
}, "");
|
||||
//console.log(insertQueries, updateQueries, removeQueries);
|
||||
|
||||
if ((insertQueries + updateQueries + removeQueries).trim() === "") {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(null);
|
||||
const {
|
||||
data: {joblines: existingLinesFromDb},
|
||||
} = await client.query({
|
||||
query: GET_ALL_JOBLINES_BY_PK,
|
||||
variables: {id: jobId},
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(gql`
|
||||
mutation SUPPLEMENT_EST_LINES{
|
||||
${insertQueries + updateQueries + removeQueries}
|
||||
const existingLines = _.cloneDeep(existingLinesFromDb);
|
||||
const linesToInsert = [];
|
||||
const linesToUpdate = [];
|
||||
|
||||
newLines.forEach((newLine) => {
|
||||
const matchingIndex = existingLines.findIndex(
|
||||
(eL) => eL.unq_seq === newLine.unq_seq
|
||||
);
|
||||
|
||||
//Should do a check to make sure there is only 1 matching unq sequence number.
|
||||
|
||||
if (matchingIndex >= 0) {
|
||||
//Found a relevant matching line. Add it to lines to update.
|
||||
linesToUpdate.push({
|
||||
id: existingLines[matchingIndex].id,
|
||||
newData: {...newLine, removed: false, act_price_before_ppc: null},
|
||||
});
|
||||
|
||||
//Splice out item we found for performance.
|
||||
existingLines.splice(matchingIndex, 1);
|
||||
} else {
|
||||
//Didn't find a match. Must be a new line.
|
||||
linesToInsert.push(newLine);
|
||||
}
|
||||
});
|
||||
|
||||
//Wahtever is left in the existing lines, are lines that should be removed.
|
||||
const insertQueries = linesToInsert.reduce((acc, value, idx) => {
|
||||
return acc + generateInsertQuery(value, idx, jobId);
|
||||
}, "");
|
||||
|
||||
const updateQueries = linesToUpdate.reduce((acc, value, idx) => {
|
||||
return acc + generateUpdateQuery(value, idx);
|
||||
}, "");
|
||||
|
||||
const removeQueries = existingLines
|
||||
.filter((l) => !l.manual_line)
|
||||
.reduce((acc, value, idx) => {
|
||||
return acc + generateRemoveQuery(value, idx);
|
||||
}, "");
|
||||
//console.log(insertQueries, updateQueries, removeQueries);
|
||||
|
||||
if ((insertQueries + updateQueries + removeQueries).trim() === "") {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(null);
|
||||
});
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(gql`
|
||||
mutation SUPPLEMENT_EST_LINES{
|
||||
${insertQueries + updateQueries + removeQueries}
|
||||
}
|
||||
`);
|
||||
});
|
||||
};
|
||||
|
||||
const generateInsertQuery = (lineToInsert, index, jobId) => {
|
||||
return `
|
||||
return `
|
||||
insert_joblines${index}: insert_joblines(objects: ${JSON.stringify({
|
||||
...lineToInsert,
|
||||
jobid: jobId,
|
||||
}).replace(/"(\w+)"\s*:/g, "$1:")}) {
|
||||
...lineToInsert,
|
||||
jobid: jobId,
|
||||
}).replace(/"(\w+)"\s*:/g, "$1:")}) {
|
||||
returning {
|
||||
id
|
||||
}
|
||||
@@ -80,13 +80,13 @@ const generateInsertQuery = (lineToInsert, index, jobId) => {
|
||||
};
|
||||
|
||||
const generateUpdateQuery = (lineToUpdate, index) => {
|
||||
return `
|
||||
return `
|
||||
update_joblines${index}: update_joblines(where: { id: { _eq: "${
|
||||
lineToUpdate.id
|
||||
}" } }, _set: ${JSON.stringify(lineToUpdate.newData).replace(
|
||||
/"(\w+)"\s*:/g,
|
||||
"$1:"
|
||||
)}) {
|
||||
lineToUpdate.id
|
||||
}" } }, _set: ${JSON.stringify(lineToUpdate.newData).replace(
|
||||
/"(\w+)"\s*:/g,
|
||||
"$1:"
|
||||
)}) {
|
||||
returning {
|
||||
id
|
||||
}
|
||||
@@ -94,7 +94,7 @@ const generateUpdateQuery = (lineToUpdate, index) => {
|
||||
};
|
||||
|
||||
const generateRemoveQuery = (lineToRemove, index) => {
|
||||
return `
|
||||
return `
|
||||
update_joblines_r${index}: update_joblines(where: {id: {_eq: "${lineToRemove.id}"}}, _set: {removed: true}) {
|
||||
returning{
|
||||
id
|
||||
|
||||
@@ -1,234 +1,234 @@
|
||||
const headerFields = [
|
||||
//AD1
|
||||
"ins_co_id",
|
||||
"ins_co_nm",
|
||||
"ins_addr1",
|
||||
"ins_addr2",
|
||||
"ins_city",
|
||||
"ins_st",
|
||||
"ins_zip",
|
||||
"ins_ctry",
|
||||
"ins_ea",
|
||||
"policy_no",
|
||||
"ded_amt",
|
||||
"ded_status",
|
||||
"asgn_no",
|
||||
"asgn_date",
|
||||
"asgn_type",
|
||||
"clm_no",
|
||||
"clm_ofc_id",
|
||||
"clm_ofc_nm",
|
||||
"clm_addr1",
|
||||
"clm_addr2",
|
||||
"clm_city",
|
||||
"clm_st",
|
||||
"clm_zip",
|
||||
"clm_ctry",
|
||||
"clm_ph1",
|
||||
"clm_ph1x",
|
||||
"clm_ph2",
|
||||
"clm_ph2x",
|
||||
"clm_fax",
|
||||
"clm_faxx",
|
||||
"clm_ct_ln",
|
||||
"clm_ct_fn",
|
||||
"clm_title",
|
||||
"clm_ct_ph",
|
||||
"clm_ct_phx",
|
||||
"clm_ea",
|
||||
"payee_nms",
|
||||
"pay_type",
|
||||
"pay_date",
|
||||
"pay_chknm",
|
||||
"pay_amt",
|
||||
"agt_co_id",
|
||||
"agt_co_nm",
|
||||
"agt_addr1",
|
||||
"agt_addr2",
|
||||
"agt_city",
|
||||
"agt_st",
|
||||
"agt_zip",
|
||||
"agt_ctry",
|
||||
"agt_ph1",
|
||||
"agt_ph1x",
|
||||
"agt_ph2",
|
||||
"agt_ph2x",
|
||||
"agt_fax",
|
||||
"agt_faxx",
|
||||
"agt_ct_ln",
|
||||
"agt_ct_fn",
|
||||
"agt_ct_ph",
|
||||
"agt_ct_phx",
|
||||
"agt_ea",
|
||||
"agt_lic_no",
|
||||
"loss_date",
|
||||
"loss_type",
|
||||
"loss_desc",
|
||||
"theft_ind",
|
||||
"cat_no",
|
||||
"tlos_ind",
|
||||
"cust_pr",
|
||||
"insd_ln",
|
||||
"insd_fn",
|
||||
"insd_title",
|
||||
"insd_co_nm",
|
||||
"insd_addr1",
|
||||
"insd_addr2",
|
||||
"insd_city",
|
||||
"insd_st",
|
||||
"insd_zip",
|
||||
"insd_ctry",
|
||||
"insd_ph1",
|
||||
"insd_ph1x",
|
||||
"insd_ph2",
|
||||
"insd_ph2x",
|
||||
"insd_fax",
|
||||
"insd_faxx",
|
||||
"insd_ea",
|
||||
"ownr_ln",
|
||||
"ownr_fn",
|
||||
"ownr_title",
|
||||
"ownr_co_nm",
|
||||
"ownr_addr1",
|
||||
"ownr_addr2",
|
||||
"ownr_city",
|
||||
"ownr_st",
|
||||
"ownr_zip",
|
||||
"ownr_ctry",
|
||||
"ownr_ph1",
|
||||
"ownr_ph1x",
|
||||
"ownr_ph2",
|
||||
"ownr_ph2x",
|
||||
"ownr_fax",
|
||||
"ownr_faxx",
|
||||
"ownr_ea",
|
||||
"ins_ph1",
|
||||
"ins_ph1x",
|
||||
"ins_ph2",
|
||||
"ins_ph2x",
|
||||
"ins_fax",
|
||||
"ins_faxx",
|
||||
"ins_ct_ln",
|
||||
"ins_ct_fn",
|
||||
"ins_title",
|
||||
"ins_ct_ph",
|
||||
"ins_ct_phx",
|
||||
"loss_cat",
|
||||
//AD2
|
||||
"clmt_ln",
|
||||
"clmt_fn",
|
||||
"clmt_title",
|
||||
"clmt_co_nm",
|
||||
"clmt_addr1",
|
||||
"clmt_addr2",
|
||||
"clmt_city",
|
||||
"clmt_st",
|
||||
"clmt_zip",
|
||||
"clmt_ctry",
|
||||
"clmt_ph1",
|
||||
"clmt_ph1x",
|
||||
"clmt_ph2",
|
||||
"clmt_ph2x",
|
||||
"clmt_fax",
|
||||
"clmt_faxx",
|
||||
"clmt_ea",
|
||||
"est_co_id",
|
||||
"est_co_nm",
|
||||
"est_addr1",
|
||||
"est_addr2",
|
||||
"est_city",
|
||||
"est_st",
|
||||
"est_zip",
|
||||
"est_ctry",
|
||||
"est_ph1",
|
||||
"est_ph1x",
|
||||
"est_ph2",
|
||||
"est_ph2x",
|
||||
"est_fax",
|
||||
"est_faxx",
|
||||
"est_ct_ln",
|
||||
"est_ct_fn",
|
||||
"est_ea",
|
||||
"est_lic_no",
|
||||
"est_fileno",
|
||||
"insp_ct_ln",
|
||||
"insp_ct_fn",
|
||||
"insp_addr1",
|
||||
"insp_addr2",
|
||||
"insp_city",
|
||||
"insp_st",
|
||||
"insp_zip",
|
||||
"insp_ctry",
|
||||
"insp_ph1",
|
||||
"insp_ph1x",
|
||||
"insp_ph2",
|
||||
"insp_ph2x",
|
||||
"insp_fax",
|
||||
"insp_faxx",
|
||||
"insp_ea",
|
||||
"insp_code",
|
||||
"insp_desc",
|
||||
"insp_date",
|
||||
"insp_time",
|
||||
"rf_co_id",
|
||||
"rf_co_nm",
|
||||
"rf_addr1",
|
||||
"rf_addr2",
|
||||
"rf_city",
|
||||
"rf_st",
|
||||
"rf_zip",
|
||||
"rf_ctry",
|
||||
"rf_ph1",
|
||||
"rf_ph1x",
|
||||
"rf_ph2",
|
||||
"rf_ph2x",
|
||||
"rf_fax",
|
||||
"rf_faxx",
|
||||
"rf_ct_ln",
|
||||
"rf_ct_fn",
|
||||
"rf_ea",
|
||||
"rf_tax_id",
|
||||
"rf_lic_no",
|
||||
"rf_bar_no",
|
||||
"ro_in_date",
|
||||
"ro_in_time",
|
||||
"tar_date",
|
||||
"tar_time",
|
||||
"ro_cmpdate",
|
||||
"ro_cmptime",
|
||||
"date_out",
|
||||
"time_out",
|
||||
"rf_estimtr",
|
||||
"mktg_type",
|
||||
"mktg_src",
|
||||
"loc_nm",
|
||||
"loc_addr1",
|
||||
"loc_addr2",
|
||||
"loc_city",
|
||||
"loc_st",
|
||||
"loc_zip",
|
||||
"loc_ctry",
|
||||
"loc_ph1",
|
||||
"loc_ph1x",
|
||||
"loc_ph2",
|
||||
"loc_ph2x",
|
||||
"loc_fax",
|
||||
"loc_faxx",
|
||||
"loc_ct_ln",
|
||||
"loc_ct_fn",
|
||||
"loc_title",
|
||||
"loc_ph",
|
||||
"loc_phx",
|
||||
"loc_ea",
|
||||
//VEH
|
||||
"plate_no",
|
||||
"plate_st",
|
||||
"v_vin",
|
||||
"v_model_yr",
|
||||
"v_make_desc",
|
||||
"v_model_desc",
|
||||
"v_options",
|
||||
"v_color",
|
||||
//AD1
|
||||
"ins_co_id",
|
||||
"ins_co_nm",
|
||||
"ins_addr1",
|
||||
"ins_addr2",
|
||||
"ins_city",
|
||||
"ins_st",
|
||||
"ins_zip",
|
||||
"ins_ctry",
|
||||
"ins_ea",
|
||||
"policy_no",
|
||||
"ded_amt",
|
||||
"ded_status",
|
||||
"asgn_no",
|
||||
"asgn_date",
|
||||
"asgn_type",
|
||||
"clm_no",
|
||||
"clm_ofc_id",
|
||||
"clm_ofc_nm",
|
||||
"clm_addr1",
|
||||
"clm_addr2",
|
||||
"clm_city",
|
||||
"clm_st",
|
||||
"clm_zip",
|
||||
"clm_ctry",
|
||||
"clm_ph1",
|
||||
"clm_ph1x",
|
||||
"clm_ph2",
|
||||
"clm_ph2x",
|
||||
"clm_fax",
|
||||
"clm_faxx",
|
||||
"clm_ct_ln",
|
||||
"clm_ct_fn",
|
||||
"clm_title",
|
||||
"clm_ct_ph",
|
||||
"clm_ct_phx",
|
||||
"clm_ea",
|
||||
"payee_nms",
|
||||
"pay_type",
|
||||
"pay_date",
|
||||
"pay_chknm",
|
||||
"pay_amt",
|
||||
"agt_co_id",
|
||||
"agt_co_nm",
|
||||
"agt_addr1",
|
||||
"agt_addr2",
|
||||
"agt_city",
|
||||
"agt_st",
|
||||
"agt_zip",
|
||||
"agt_ctry",
|
||||
"agt_ph1",
|
||||
"agt_ph1x",
|
||||
"agt_ph2",
|
||||
"agt_ph2x",
|
||||
"agt_fax",
|
||||
"agt_faxx",
|
||||
"agt_ct_ln",
|
||||
"agt_ct_fn",
|
||||
"agt_ct_ph",
|
||||
"agt_ct_phx",
|
||||
"agt_ea",
|
||||
"agt_lic_no",
|
||||
"loss_date",
|
||||
"loss_type",
|
||||
"loss_desc",
|
||||
"theft_ind",
|
||||
"cat_no",
|
||||
"tlos_ind",
|
||||
"cust_pr",
|
||||
"insd_ln",
|
||||
"insd_fn",
|
||||
"insd_title",
|
||||
"insd_co_nm",
|
||||
"insd_addr1",
|
||||
"insd_addr2",
|
||||
"insd_city",
|
||||
"insd_st",
|
||||
"insd_zip",
|
||||
"insd_ctry",
|
||||
"insd_ph1",
|
||||
"insd_ph1x",
|
||||
"insd_ph2",
|
||||
"insd_ph2x",
|
||||
"insd_fax",
|
||||
"insd_faxx",
|
||||
"insd_ea",
|
||||
"ownr_ln",
|
||||
"ownr_fn",
|
||||
"ownr_title",
|
||||
"ownr_co_nm",
|
||||
"ownr_addr1",
|
||||
"ownr_addr2",
|
||||
"ownr_city",
|
||||
"ownr_st",
|
||||
"ownr_zip",
|
||||
"ownr_ctry",
|
||||
"ownr_ph1",
|
||||
"ownr_ph1x",
|
||||
"ownr_ph2",
|
||||
"ownr_ph2x",
|
||||
"ownr_fax",
|
||||
"ownr_faxx",
|
||||
"ownr_ea",
|
||||
"ins_ph1",
|
||||
"ins_ph1x",
|
||||
"ins_ph2",
|
||||
"ins_ph2x",
|
||||
"ins_fax",
|
||||
"ins_faxx",
|
||||
"ins_ct_ln",
|
||||
"ins_ct_fn",
|
||||
"ins_title",
|
||||
"ins_ct_ph",
|
||||
"ins_ct_phx",
|
||||
"loss_cat",
|
||||
//AD2
|
||||
"clmt_ln",
|
||||
"clmt_fn",
|
||||
"clmt_title",
|
||||
"clmt_co_nm",
|
||||
"clmt_addr1",
|
||||
"clmt_addr2",
|
||||
"clmt_city",
|
||||
"clmt_st",
|
||||
"clmt_zip",
|
||||
"clmt_ctry",
|
||||
"clmt_ph1",
|
||||
"clmt_ph1x",
|
||||
"clmt_ph2",
|
||||
"clmt_ph2x",
|
||||
"clmt_fax",
|
||||
"clmt_faxx",
|
||||
"clmt_ea",
|
||||
"est_co_id",
|
||||
"est_co_nm",
|
||||
"est_addr1",
|
||||
"est_addr2",
|
||||
"est_city",
|
||||
"est_st",
|
||||
"est_zip",
|
||||
"est_ctry",
|
||||
"est_ph1",
|
||||
"est_ph1x",
|
||||
"est_ph2",
|
||||
"est_ph2x",
|
||||
"est_fax",
|
||||
"est_faxx",
|
||||
"est_ct_ln",
|
||||
"est_ct_fn",
|
||||
"est_ea",
|
||||
"est_lic_no",
|
||||
"est_fileno",
|
||||
"insp_ct_ln",
|
||||
"insp_ct_fn",
|
||||
"insp_addr1",
|
||||
"insp_addr2",
|
||||
"insp_city",
|
||||
"insp_st",
|
||||
"insp_zip",
|
||||
"insp_ctry",
|
||||
"insp_ph1",
|
||||
"insp_ph1x",
|
||||
"insp_ph2",
|
||||
"insp_ph2x",
|
||||
"insp_fax",
|
||||
"insp_faxx",
|
||||
"insp_ea",
|
||||
"insp_code",
|
||||
"insp_desc",
|
||||
"insp_date",
|
||||
"insp_time",
|
||||
"rf_co_id",
|
||||
"rf_co_nm",
|
||||
"rf_addr1",
|
||||
"rf_addr2",
|
||||
"rf_city",
|
||||
"rf_st",
|
||||
"rf_zip",
|
||||
"rf_ctry",
|
||||
"rf_ph1",
|
||||
"rf_ph1x",
|
||||
"rf_ph2",
|
||||
"rf_ph2x",
|
||||
"rf_fax",
|
||||
"rf_faxx",
|
||||
"rf_ct_ln",
|
||||
"rf_ct_fn",
|
||||
"rf_ea",
|
||||
"rf_tax_id",
|
||||
"rf_lic_no",
|
||||
"rf_bar_no",
|
||||
"ro_in_date",
|
||||
"ro_in_time",
|
||||
"tar_date",
|
||||
"tar_time",
|
||||
"ro_cmpdate",
|
||||
"ro_cmptime",
|
||||
"date_out",
|
||||
"time_out",
|
||||
"rf_estimtr",
|
||||
"mktg_type",
|
||||
"mktg_src",
|
||||
"loc_nm",
|
||||
"loc_addr1",
|
||||
"loc_addr2",
|
||||
"loc_city",
|
||||
"loc_st",
|
||||
"loc_zip",
|
||||
"loc_ctry",
|
||||
"loc_ph1",
|
||||
"loc_ph1x",
|
||||
"loc_ph2",
|
||||
"loc_ph2x",
|
||||
"loc_fax",
|
||||
"loc_faxx",
|
||||
"loc_ct_ln",
|
||||
"loc_ct_fn",
|
||||
"loc_title",
|
||||
"loc_ph",
|
||||
"loc_phx",
|
||||
"loc_ea",
|
||||
//VEH
|
||||
"plate_no",
|
||||
"plate_st",
|
||||
"v_vin",
|
||||
"v_model_yr",
|
||||
"v_make_desc",
|
||||
"v_model_desc",
|
||||
"v_options",
|
||||
"v_color",
|
||||
];
|
||||
|
||||
export default headerFields;
|
||||
|
||||
@@ -1,262 +1,254 @@
|
||||
import {
|
||||
DeleteFilled,
|
||||
DownloadOutlined,
|
||||
PlusCircleFilled,
|
||||
SyncOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { Alert, Button, Card, Input, notification, Space, Table } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { Link } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import {
|
||||
DELETE_ALL_AVAILABLE_JOBS,
|
||||
DELETE_AVAILABLE_JOB,
|
||||
} from "../../graphql/available-jobs.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import {DeleteFilled, DownloadOutlined, PlusCircleFilled, SyncOutlined,} from "@ant-design/icons";
|
||||
import {useMutation} from "@apollo/client";
|
||||
import {Alert, Button, Card, Input, notification, Space, Table} from "antd";
|
||||
import React, {useState} from "react";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {connect} from "react-redux";
|
||||
import {Link} from "react-router-dom";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {DELETE_ALL_AVAILABLE_JOBS, DELETE_AVAILABLE_JOB,} from "../../graphql/available-jobs.queries";
|
||||
import {selectBodyshop} from "../../redux/user/user.selectors";
|
||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||
import { TimeAgoFormatter } from "../../utils/DateFormatter";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
import {TimeAgoFormatter} from "../../utils/DateFormatter";
|
||||
import {alphaSort} from "../../utils/sorters";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(JobsAvailableComponent);
|
||||
|
||||
export function JobsAvailableComponent({
|
||||
bodyshop,
|
||||
loading,
|
||||
data,
|
||||
refetch,
|
||||
addJobAsNew,
|
||||
addJobAsSupp,
|
||||
}) {
|
||||
const [deleteAllAvailableJobs] = useMutation(DELETE_ALL_AVAILABLE_JOBS);
|
||||
const [deleteJob] = useMutation(DELETE_AVAILABLE_JOB);
|
||||
const { t } = useTranslation();
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
filteredInfo: { text: "" },
|
||||
});
|
||||
bodyshop,
|
||||
loading,
|
||||
data,
|
||||
refetch,
|
||||
addJobAsNew,
|
||||
addJobAsSupp,
|
||||
}) {
|
||||
const [deleteAllAvailableJobs] = useMutation(DELETE_ALL_AVAILABLE_JOBS);
|
||||
const [deleteJob] = useMutation(DELETE_AVAILABLE_JOB);
|
||||
const {t} = useTranslation();
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
filteredInfo: {text: ""},
|
||||
});
|
||||
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
||||
};
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setState({...state, filteredInfo: filters, sortedInfo: sorter});
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("jobs.fields.cieca_id"),
|
||||
dataIndex: "cieca_id",
|
||||
key: "cieca_id",
|
||||
sorter: (a, b) => alphaSort(a.cieca_id, b.cieca_id),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.ro_number"),
|
||||
dataIndex: "job_id",
|
||||
key: "job_id",
|
||||
//width: "8%",
|
||||
// onFilter: (value, record) => record.ro_number.includes(value),
|
||||
// filteredValue: state.filteredInfo.text || null,
|
||||
sorter: (a, b) =>
|
||||
alphaSort(a.job && a.job.ro_number, b.job && b.job.ro_number),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "job_id" && state.sortedInfo.order,
|
||||
render: (text, record) =>
|
||||
record.job ? (
|
||||
<Link to={`/manage/jobs/${record.job.id}`}>
|
||||
{(record.job && record.job.ro_number) || t("general.labels.na")}
|
||||
</Link>
|
||||
) : (
|
||||
<div>
|
||||
{(record.job && record.job.ro_number) || t("general.labels.na")}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.owner"),
|
||||
dataIndex: "ownr_name",
|
||||
key: "ownr_name",
|
||||
ellipsis: true,
|
||||
sorter: (a, b) => alphaSort(a.ownr_name, b.ownr_name),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "ownr_name" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.vehicle"),
|
||||
dataIndex: "vehicle_info",
|
||||
key: "vehicle_info",
|
||||
sorter: (a, b) => alphaSort(a.vehicle_info, b.vehicle_info),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "vehicle_info" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.clm_no"),
|
||||
dataIndex: "clm_no",
|
||||
key: "clm_no",
|
||||
sorter: (a, b) => alphaSort(a.clm_no, b.clm_no),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "clm_no" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.ins_co_nm"),
|
||||
dataIndex: "ins_co_nm",
|
||||
key: "ins_co_nm",
|
||||
sorter: (a, b) => alphaSort(a.ins_co_nm, b.ins_co_nm),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "ins_co_nm" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.clm_total"),
|
||||
dataIndex: "clm_amt",
|
||||
key: "clm_amt",
|
||||
sorter: (a, b) => a.clm_amt - b.clm_amt,
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "clm_amt" && state.sortedInfo.order,
|
||||
render: (text, record) => (
|
||||
<CurrencyFormatter>{record.clm_amt}</CurrencyFormatter>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.uploaded_by"),
|
||||
dataIndex: "uploaded_by",
|
||||
key: "uploaded_by",
|
||||
sorter: (a, b) => alphaSort(a.uploaded_by, b.uploaded_by),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "uploaded_by" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.updated_at"),
|
||||
dataIndex: "updated_at",
|
||||
key: "updated_at",
|
||||
sorter: (a, b) => new Date(a.updated_at) - new Date(b.updated_at),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "updated_at" && state.sortedInfo.order,
|
||||
render: (text, record) => (
|
||||
<TimeAgoFormatter>{record.updated_at}</TimeAgoFormatter>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("general.labels.actions"),
|
||||
key: "actions",
|
||||
render: (text, record) => {
|
||||
const isClosed =
|
||||
record.job &&
|
||||
(record.job.status === bodyshop.md_ro_statuses.default_exported ||
|
||||
record.job.status === bodyshop.md_ro_statuses.default_invoiced);
|
||||
return (
|
||||
<Space wrap>
|
||||
<Button
|
||||
onClick={() => {
|
||||
deleteJob({ variables: { id: record.id } }).then((r) => {
|
||||
notification["success"]({
|
||||
message: t("jobs.successes.deleted"),
|
||||
});
|
||||
refetch();
|
||||
});
|
||||
}}
|
||||
>
|
||||
<DeleteFilled />
|
||||
</Button>
|
||||
{!isClosed && (
|
||||
<>
|
||||
<Button
|
||||
onClick={() => addJobAsNew(record)}
|
||||
disabled={record.issupplement}
|
||||
>
|
||||
<PlusCircleFilled />
|
||||
</Button>
|
||||
<Button onClick={() => addJobAsSupp(record)}>
|
||||
<DownloadOutlined />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{isClosed && (
|
||||
<Alert
|
||||
type="error"
|
||||
message={t("jobs.labels.alreadyclosed")}
|
||||
></Alert>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
const columns = [
|
||||
{
|
||||
title: t("jobs.fields.cieca_id"),
|
||||
dataIndex: "cieca_id",
|
||||
key: "cieca_id",
|
||||
sorter: (a, b) => alphaSort(a.cieca_id, b.cieca_id),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.ro_number"),
|
||||
dataIndex: "job_id",
|
||||
key: "job_id",
|
||||
//width: "8%",
|
||||
// onFilter: (value, record) => record.ro_number.includes(value),
|
||||
// filteredValue: state.filteredInfo.text || null,
|
||||
sorter: (a, b) =>
|
||||
alphaSort(a.job && a.job.ro_number, b.job && b.job.ro_number),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "job_id" && state.sortedInfo.order,
|
||||
render: (text, record) =>
|
||||
record.job ? (
|
||||
<Link to={`/manage/jobs/${record.job.id}`}>
|
||||
{(record.job && record.job.ro_number) || t("general.labels.na")}
|
||||
</Link>
|
||||
) : (
|
||||
<div>
|
||||
{(record.job && record.job.ro_number) || t("general.labels.na")}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.owner"),
|
||||
dataIndex: "ownr_name",
|
||||
key: "ownr_name",
|
||||
ellipsis: true,
|
||||
sorter: (a, b) => alphaSort(a.ownr_name, b.ownr_name),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "ownr_name" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.vehicle"),
|
||||
dataIndex: "vehicle_info",
|
||||
key: "vehicle_info",
|
||||
sorter: (a, b) => alphaSort(a.vehicle_info, b.vehicle_info),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "vehicle_info" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.clm_no"),
|
||||
dataIndex: "clm_no",
|
||||
key: "clm_no",
|
||||
sorter: (a, b) => alphaSort(a.clm_no, b.clm_no),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "clm_no" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.ins_co_nm"),
|
||||
dataIndex: "ins_co_nm",
|
||||
key: "ins_co_nm",
|
||||
sorter: (a, b) => alphaSort(a.ins_co_nm, b.ins_co_nm),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "ins_co_nm" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.clm_total"),
|
||||
dataIndex: "clm_amt",
|
||||
key: "clm_amt",
|
||||
sorter: (a, b) => a.clm_amt - b.clm_amt,
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "clm_amt" && state.sortedInfo.order,
|
||||
render: (text, record) => (
|
||||
<CurrencyFormatter>{record.clm_amt}</CurrencyFormatter>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.uploaded_by"),
|
||||
dataIndex: "uploaded_by",
|
||||
key: "uploaded_by",
|
||||
sorter: (a, b) => alphaSort(a.uploaded_by, b.uploaded_by),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "uploaded_by" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.updated_at"),
|
||||
dataIndex: "updated_at",
|
||||
key: "updated_at",
|
||||
sorter: (a, b) => new Date(a.updated_at) - new Date(b.updated_at),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "updated_at" && state.sortedInfo.order,
|
||||
render: (text, record) => (
|
||||
<TimeAgoFormatter>{record.updated_at}</TimeAgoFormatter>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t("general.labels.actions"),
|
||||
key: "actions",
|
||||
render: (text, record) => {
|
||||
const isClosed =
|
||||
record.job &&
|
||||
(record.job.status === bodyshop.md_ro_statuses.default_exported ||
|
||||
record.job.status === bodyshop.md_ro_statuses.default_invoiced);
|
||||
return (
|
||||
<Space wrap>
|
||||
<Button
|
||||
onClick={() => {
|
||||
deleteJob({variables: {id: record.id}}).then((r) => {
|
||||
notification["success"]({
|
||||
message: t("jobs.successes.deleted"),
|
||||
});
|
||||
refetch();
|
||||
});
|
||||
}}
|
||||
>
|
||||
<DeleteFilled/>
|
||||
</Button>
|
||||
{!isClosed && (
|
||||
<>
|
||||
<Button
|
||||
onClick={() => addJobAsNew(record)}
|
||||
disabled={record.issupplement}
|
||||
>
|
||||
<PlusCircleFilled/>
|
||||
</Button>
|
||||
<Button onClick={() => addJobAsSupp(record)}>
|
||||
<DownloadOutlined/>
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{isClosed && (
|
||||
<Alert
|
||||
type="error"
|
||||
message={t("jobs.labels.alreadyclosed")}
|
||||
></Alert>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const availableJobs = data
|
||||
? searchText
|
||||
? data.available_jobs.filter(
|
||||
(j) =>
|
||||
(j.ownr_name || "")
|
||||
.toLowerCase()
|
||||
.includes(searchText.toLowerCase()) ||
|
||||
(j.vehicle_info || "")
|
||||
.toLowerCase()
|
||||
.includes(searchText.toLowerCase()) ||
|
||||
(j.clm_no || "").toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
: data.available_jobs
|
||||
: [];
|
||||
const availableJobs = data
|
||||
? searchText
|
||||
? data.available_jobs.filter(
|
||||
(j) =>
|
||||
(j.ownr_name || "")
|
||||
.toLowerCase()
|
||||
.includes(searchText.toLowerCase()) ||
|
||||
(j.vehicle_info || "")
|
||||
.toLowerCase()
|
||||
.includes(searchText.toLowerCase()) ||
|
||||
(j.clm_no || "").toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
: data.available_jobs
|
||||
: [];
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={t("jobs.labels.availablejobs")}
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
onClick={() => {
|
||||
refetch();
|
||||
}}
|
||||
>
|
||||
<SyncOutlined />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
deleteAllAvailableJobs()
|
||||
.then((r) => {
|
||||
notification["success"]({
|
||||
message: t("jobs.successes.all_deleted", {
|
||||
count: r.data.delete_available_jobs.affected_rows,
|
||||
}),
|
||||
});
|
||||
refetch();
|
||||
})
|
||||
.catch((r) => {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.deleted") + " " + r.message,
|
||||
});
|
||||
});
|
||||
}}
|
||||
>
|
||||
{t("general.actions.deleteall")}
|
||||
</Button>
|
||||
return (
|
||||
<Card
|
||||
title={t("jobs.labels.availablejobs")}
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
onClick={() => {
|
||||
refetch();
|
||||
}}
|
||||
>
|
||||
<SyncOutlined/>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
deleteAllAvailableJobs()
|
||||
.then((r) => {
|
||||
notification["success"]({
|
||||
message: t("jobs.successes.all_deleted", {
|
||||
count: r.data.delete_available_jobs.affected_rows,
|
||||
}),
|
||||
});
|
||||
refetch();
|
||||
})
|
||||
.catch((r) => {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.deleted") + " " + r.message,
|
||||
});
|
||||
});
|
||||
}}
|
||||
>
|
||||
{t("general.actions.deleteall")}
|
||||
</Button>
|
||||
|
||||
<Input.Search
|
||||
placeholder={t("general.labels.search")}
|
||||
onChange={(e) => {
|
||||
setSearchText(e.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={availableJobs}
|
||||
onChange={handleTableChange}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
<Input.Search
|
||||
placeholder={t("general.labels.search")}
|
||||
onChange={(e) => {
|
||||
setSearchText(e.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={availableJobs}
|
||||
onChange={handleTableChange}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user