From 04c7bc445b26929dd5964cc127e466ee40d0380b Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Fri, 10 Nov 2023 16:32:38 -0800 Subject: [PATCH] IO-2448 Search by C/C Plate number --- .../contracts-list.component.jsx | 4 +- .../courtesy-cars-list.component.jsx | 1 + .../1699662574943_run_sql_migration/down.sql | 38 +++++++++++++++++++ .../1699662574943_run_sql_migration/up.sql | 36 ++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 hasura/migrations/1699662574943_run_sql_migration/down.sql create mode 100644 hasura/migrations/1699662574943_run_sql_migration/up.sql diff --git a/client/src/components/contracts-list/contracts-list.component.jsx b/client/src/components/contracts-list/contracts-list.component.jsx index 2d5576565..fa9439c65 100644 --- a/client/src/components/contracts-list/contracts-list.component.jsx +++ b/client/src/components/contracts-list/contracts-list.component.jsx @@ -4,14 +4,14 @@ import queryString from "query-string"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useHistory, useLocation } from "react-router-dom"; +import { setModalContext } from "../../redux/modals/modals.actions"; import { DateTimeFormatter } from "../../utils/DateFormatter"; import { alphaSort } from "../../utils/sorters"; import ContractsFindModalContainer from "../contracts-find-modal/contracts-find-modal.container"; -import { setModalContext } from "../../redux/modals/modals.actions"; +import moment from "moment"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; -import moment from "moment"; import { selectBodyshop } from "../../redux/user/user.selectors"; const mapStateToProps = createStructuredSelector({ diff --git a/client/src/components/courtesy-cars-list/courtesy-cars-list.component.jsx b/client/src/components/courtesy-cars-list/courtesy-cars-list.component.jsx index b2e3059f6..ab85f95bc 100644 --- a/client/src/components/courtesy-cars-list/courtesy-cars-list.component.jsx +++ b/client/src/components/courtesy-cars-list/courtesy-cars-list.component.jsx @@ -174,6 +174,7 @@ export default function CourtesyCarsList({ loading, courtesycars, refetch }) { (c.year || "").toLowerCase().includes(searchText.toLowerCase()) || (c.make || "").toLowerCase().includes(searchText.toLowerCase()) || (c.model || "").toLowerCase().includes(searchText.toLowerCase()) || + (c.plate || "").toLowerCase().includes(searchText.toLowerCase()) || (t(c.status) || "").toLowerCase().includes(searchText.toLowerCase()) ) : courtesycars; diff --git a/hasura/migrations/1699662574943_run_sql_migration/down.sql b/hasura/migrations/1699662574943_run_sql_migration/down.sql new file mode 100644 index 000000000..15712cc8f --- /dev/null +++ b/hasura/migrations/1699662574943_run_sql_migration/down.sql @@ -0,0 +1,38 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- CREATE OR REPLACE FUNCTION public.search_cccontracts(search text) +-- RETURNS SETOF cccontracts +-- LANGUAGE plpgsql +-- STABLE +-- AS $function$ +-- BEGIN +-- IF search = '' THEN +-- RETURN query +-- SELECT +-- * +-- FROM +-- cccontracts c; +-- ELSE +-- RETURN query +-- SELECT +-- contracts.* +-- FROM +-- courtesycars cars, +-- jobs jobs, +-- cccontracts contracts +-- WHERE (jobs.ro_number ILIKE '%' || search || '%' +-- OR jobs.ownr_fn ILIKE '%' || search || '%' +-- OR jobs.ownr_ln ILIKE '%' || search || '%' +-- OR jobs.ownr_co_nm ILIKE '%' || search || '%' +-- OR (cast(contracts.agreementnumber as text)) ILIKE '%' || search || '%' +-- OR contracts.driver_fn ILIKE '%' || search || '%' +-- OR contracts.driver_ln ILIKE '%' || search || '%' +-- OR cars.fleetnumber ILIKE '%' || search || '%' +-- OR cars.make ILIKE '%' || search || '%' +-- OR cars.model ILIKE '%' || search || '%' +-- OR cars.plate ILIKE '%' || search || '%') +-- AND contracts.jobid = jobs.id +-- AND contracts.courtesycarid = cars.id; +-- END IF; +-- END +-- $function$; diff --git a/hasura/migrations/1699662574943_run_sql_migration/up.sql b/hasura/migrations/1699662574943_run_sql_migration/up.sql new file mode 100644 index 000000000..ecd8252bd --- /dev/null +++ b/hasura/migrations/1699662574943_run_sql_migration/up.sql @@ -0,0 +1,36 @@ +CREATE OR REPLACE FUNCTION public.search_cccontracts(search text) + RETURNS SETOF cccontracts + LANGUAGE plpgsql + STABLE +AS $function$ +BEGIN + IF search = '' THEN + RETURN query + SELECT + * + FROM + cccontracts c; + ELSE + RETURN query + SELECT + contracts.* + FROM + courtesycars cars, + jobs jobs, + cccontracts contracts + WHERE (jobs.ro_number ILIKE '%' || search || '%' + OR jobs.ownr_fn ILIKE '%' || search || '%' + OR jobs.ownr_ln ILIKE '%' || search || '%' + OR jobs.ownr_co_nm ILIKE '%' || search || '%' + OR (cast(contracts.agreementnumber as text)) ILIKE '%' || search || '%' + OR contracts.driver_fn ILIKE '%' || search || '%' + OR contracts.driver_ln ILIKE '%' || search || '%' + OR cars.fleetnumber ILIKE '%' || search || '%' + OR cars.make ILIKE '%' || search || '%' + OR cars.model ILIKE '%' || search || '%' + OR cars.plate ILIKE '%' || search || '%') + AND contracts.jobid = jobs.id + AND contracts.courtesycarid = cars.id; + END IF; +END +$function$;