lot name contains, starts with, or ends with
parent
69c97d0d02
commit
75ced51d7e
|
|
@ -8,6 +8,7 @@ interface GetLotOccupanciesFilters {
|
|||
occupantName?: string;
|
||||
occupancyTypeId?: number | string;
|
||||
mapId?: number | string;
|
||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
||||
lotName?: string;
|
||||
lotTypeId?: number | string;
|
||||
workOrderId?: number | string;
|
||||
|
|
|
|||
|
|
@ -15,12 +15,22 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => {
|
|||
sqlParameters.push(filters.lotId);
|
||||
}
|
||||
if (filters.lotName) {
|
||||
if (filters.lotNameSearchType === "startsWith") {
|
||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
||||
sqlParameters.push(filters.lotName);
|
||||
}
|
||||
else if (filters.lotNameSearchType === "endsWith") {
|
||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
||||
sqlParameters.push(filters.lotName);
|
||||
}
|
||||
else {
|
||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
||||
for (const lotNamePiece of lotNamePieces) {
|
||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
||||
sqlParameters.push(lotNamePiece);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filters.occupantName) {
|
||||
const occupantNamePieces = filters.occupantName.toLowerCase().split(" ");
|
||||
for (const occupantNamePiece of occupantNamePieces) {
|
||||
|
|
@ -36,21 +46,24 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => {
|
|||
if (filters.occupancyTime) {
|
||||
const currentDateString = dateToInteger(new Date());
|
||||
switch (filters.occupancyTime) {
|
||||
case "current":
|
||||
case "current": {
|
||||
sqlWhereClause +=
|
||||
" and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)";
|
||||
sqlParameters.push(currentDateString, currentDateString);
|
||||
break;
|
||||
case "past":
|
||||
}
|
||||
case "past": {
|
||||
sqlWhereClause += " and o.occupancyEndDate < ?";
|
||||
sqlParameters.push(currentDateString);
|
||||
break;
|
||||
case "future":
|
||||
}
|
||||
case "future": {
|
||||
sqlWhereClause += " and o.occupancyStartDate > ?";
|
||||
sqlParameters.push(currentDateString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filters.occupancyStartDateString) {
|
||||
sqlWhereClause += " and o.occupancyStartDate = ?";
|
||||
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ interface GetLotOccupanciesFilters {
|
|||
occupantName?: string;
|
||||
occupancyTypeId?: number | string;
|
||||
mapId?: number | string;
|
||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
||||
lotName?: string;
|
||||
lotTypeId?: number | string;
|
||||
workOrderId?: number | string;
|
||||
|
|
@ -57,12 +58,20 @@ export const getLotOccupancies = (
|
|||
}
|
||||
|
||||
if (filters.lotName) {
|
||||
if (filters.lotNameSearchType === "startsWith") {
|
||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
||||
sqlParameters.push(filters.lotName);
|
||||
} else if (filters.lotNameSearchType === "endsWith") {
|
||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
||||
sqlParameters.push(filters.lotName);
|
||||
} else {
|
||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
||||
for (const lotNamePiece of lotNamePieces) {
|
||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
||||
sqlParameters.push(lotNamePiece);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.occupantName) {
|
||||
const occupantNamePieces = filters.occupantName.toLowerCase().split(" ");
|
||||
|
|
@ -82,23 +91,26 @@ export const getLotOccupancies = (
|
|||
const currentDateString = dateToInteger(new Date());
|
||||
|
||||
switch (filters.occupancyTime) {
|
||||
case "current":
|
||||
case "current": {
|
||||
sqlWhereClause +=
|
||||
" and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)";
|
||||
sqlParameters.push(currentDateString, currentDateString);
|
||||
break;
|
||||
}
|
||||
|
||||
case "past":
|
||||
case "past": {
|
||||
sqlWhereClause += " and o.occupancyEndDate < ?";
|
||||
sqlParameters.push(currentDateString);
|
||||
break;
|
||||
}
|
||||
|
||||
case "future":
|
||||
case "future": {
|
||||
sqlWhereClause += " and o.occupancyStartDate > ?";
|
||||
sqlParameters.push(currentDateString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filters.occupancyStartDateString) {
|
||||
sqlWhereClause += " and o.occupancyStartDate = ?";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface GetLotsFilters {
|
||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
||||
lotName?: string;
|
||||
mapId?: number | string;
|
||||
lotTypeId?: number | string;
|
||||
|
|
|
|||
|
|
@ -10,12 +10,22 @@ export const getLots = (filters, options, connectedDatabase) => {
|
|||
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
||||
const sqlParameters = [];
|
||||
if (filters.lotName) {
|
||||
if (filters.lotNameSearchType === "startsWith") {
|
||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
||||
sqlParameters.push(filters.lotName);
|
||||
}
|
||||
else if (filters.lotNameSearchType === "endsWith") {
|
||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
||||
sqlParameters.push(filters.lotName);
|
||||
}
|
||||
else {
|
||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
||||
for (const lotNamePiece of lotNamePieces) {
|
||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
||||
sqlParameters.push(lotNamePiece);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filters.mapId) {
|
||||
sqlWhereClause += " and l.mapId = ?";
|
||||
sqlParameters.push(filters.mapId);
|
||||
|
|
@ -33,8 +43,7 @@ export const getLots = (filters, options, connectedDatabase) => {
|
|||
sqlWhereClause += " and lotOccupancyCount > 0";
|
||||
}
|
||||
else if (filters.occupancyStatus === "unoccupied") {
|
||||
sqlWhereClause +=
|
||||
" and (lotOccupancyCount is null or lotOccupancyCount = 0)";
|
||||
sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)";
|
||||
}
|
||||
}
|
||||
if (filters.workOrderId) {
|
||||
|
|
@ -88,12 +97,7 @@ export const getLots = (filters, options, connectedDatabase) => {
|
|||
") o on l.lotId = o.lotId") +
|
||||
sqlWhereClause +
|
||||
" order by userFn_lotNameSortName(l.lotName), l.lotId" +
|
||||
(options
|
||||
? " limit " +
|
||||
options.limit +
|
||||
" offset " +
|
||||
options.offset
|
||||
: ""))
|
||||
(options ? " limit " + options.limit + " offset " + options.offset : ""))
|
||||
.all(sqlParameters);
|
||||
if (options.limit === -1) {
|
||||
count = lots.length;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import * as configFunctions from "../functions.config.js";
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface GetLotsFilters {
|
||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
||||
lotName?: string;
|
||||
mapId?: number | string;
|
||||
lotTypeId?: number | string;
|
||||
|
|
@ -40,12 +41,21 @@ export const getLots = (
|
|||
const sqlParameters = [];
|
||||
|
||||
if (filters.lotName) {
|
||||
if (filters.lotNameSearchType === "startsWith") {
|
||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
||||
sqlParameters.push(filters.lotName);
|
||||
} else if (filters.lotNameSearchType === "endsWith") {
|
||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
||||
sqlParameters.push(filters.lotName);
|
||||
} else {
|
||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
||||
for (const lotNamePiece of lotNamePieces) {
|
||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
||||
sqlParameters.push(lotNamePiece);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (filters.mapId) {
|
||||
sqlWhereClause += " and l.mapId = ?";
|
||||
|
|
@ -66,8 +76,7 @@ export const getLots = (
|
|||
if (filters.occupancyStatus === "occupied") {
|
||||
sqlWhereClause += " and lotOccupancyCount > 0";
|
||||
} else if (filters.occupancyStatus === "unoccupied") {
|
||||
sqlWhereClause +=
|
||||
" and (lotOccupancyCount is null or lotOccupancyCount = 0)";
|
||||
sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,12 +143,7 @@ export const getLots = (
|
|||
") o on l.lotId = o.lotId") +
|
||||
sqlWhereClause +
|
||||
" order by userFn_lotNameSortName(l.lotName), l.lotId" +
|
||||
(options
|
||||
? " limit " +
|
||||
options.limit +
|
||||
" offset " +
|
||||
options.offset
|
||||
: "")
|
||||
(options ? " limit " + options.limit + " offset " + options.offset : "")
|
||||
)
|
||||
.all(sqlParameters);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,14 +34,23 @@
|
|||
<input id="searchFilter--offset" name="offset" type="hidden" value="0" />
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label" for="searchFilter--lotName"><%= configFunctions.getProperty("aliases.lot") %></label>
|
||||
<div class="field has-addons">
|
||||
<div class="control has-icons-left">
|
||||
<input class="input" id="searchFilter--lotName" name="lotName" accesskey="f" />
|
||||
<div class="select">
|
||||
<select id="selectFilter--lotNameSearchType" name="lotNameSearchType">
|
||||
<option value="">contains</option>
|
||||
<option value="startsWith">starts with</option>
|
||||
<option value="endsWith">ends with</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-search" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="control is-expanded">
|
||||
<input class="input" id="searchFilter--lotName" name="lotName" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
|
|
|
|||
|
|
@ -107,17 +107,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label" for="searchFilter--lotName"><%= configFunctions.getProperty("aliases.lot") %></label>
|
||||
<div class="control has-icons-left">
|
||||
<input class="input" id="searchFilter--lotName" name="lotName" />
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-search" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label" for="searchFilter--lotTypeId"><%= configFunctions.getProperty("aliases.lot") %> Type</label>
|
||||
|
|
@ -137,6 +126,24 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<label class="label" for="searchFilter--lotName"><%= configFunctions.getProperty("aliases.lot") %></label>
|
||||
<div class="field has-addons">
|
||||
<div class="control has-icons-left">
|
||||
<div class="select">
|
||||
<select id="selectFilter--lotNameSearchType" name="lotNameSearchType">
|
||||
<option value="">contains</option>
|
||||
<option value="startsWith">starts with</option>
|
||||
<option value="endsWith">ends with</option>
|
||||
</select>
|
||||
</div>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-search" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="control is-expanded">
|
||||
<input class="input" id="searchFilter--lotName" name="lotName" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue