====== pears.NetOwnerContactSearch ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetOwnerContactSearch"( in "pWebUserID" char(20),in "SearchValue" char(20) default '%',in "SearchState" char(5) default null,in "pSlice" integer default 1,in "pSliceSize" integer default 20 )
result( "EmploymentID" char(20),"Name" char(61),"CompanyName" char(100),"address" char(60),"Jobtitle" char(50),"status" char(50),"Alert" char(255),"IsFavourite" integer )
// IQXWeb
begin
declare "x" integer;
declare "y" integer;
declare "pStaffID" char(20);
set "pStaffID" = (select first "StaffID" from "iqxnetuser" where "iqxnetuser"."iqxnetuserid" = "pWebUserID");
set "x" = "pSliceSize";
set "y" = "x"*"pSlice"+1;
set "SearchValue" = "trim"("replace"("isnull"("SearchValue",''),'*',''));
if "trim"("isnull"("SearchState",'')) = '' then
set "SearchState" = '%'
end if;
select top "x" start at "y"
"e"."employmentid" as "EmploymentID",
"p"."forenames"+' '+"p"."surname" as "Name",
"c"."name" as "CompanyName",
"c"."town" as "address",
"e"."position" as "JobTitle",
"companystatus"."name" as "status",
"c"."alert" as "Alert",
if(select "count"() from "favourites" where "ID" = "e"."employmentid" and "Staffid" = "pStaffID") > 0 then 1 else 0 endif as "IsFavourite"
from "person" as "p" key join "employment" as "e" key join "company" as "c" key left outer join "companystatus"
where "isnull"("c"."divisionid",'') = any(select "DivisionID" from "DashboardStaffDivisions"())
and "c"."status" like "SearchState"
and "p"."status" = 'L'
and "SearchValue" <> ''
and "p"."keyname" like "SearchValue"+'%'
order by "p"."KeyName" asc
end /* DOC
2016-09-19 PC alter routine to allow search, and paging
2017-04-10 PC alter to allow all categories
2018-05-16 GJ Updated to use MHS function to obey divisions & tidied up test
inputs:
pWebUserID
SearchValue
SearchState
pSlice
pSliceSize
outputs:
EmploymentID
Name
CompanyName
address
Jobtitle
status
Alert
IsFavourite
tests:
null pWebUserID
invalid pWebUserID
null SearchValue and pSearchState
create test category
null SearchValue and test pSearchState
incorrect SearchValue and test pSearchState
create three test divisions
check default division
check assigned divisions
check all divisions
check isFavourite
*/
/* TEST
call NetTestSetup('');
update company set divisionid=null where companyid='test';
update person set keyname='testxxxyyyzzz',status='L' where personid='test';
update staff set divisionid=null,DivisionAccess=0 where staffid='TEST';
delete from divisionaccess where staffid='TEST';
delete from favourites where staffid='TEST';
select * from "NetOwnerContactSearch"( null,null,null,0, 20);
expect EOF;
select * from "NetOwnerContactSearch"( 'z99',null,null,0, 20);
expect EOF;
update staff set divisionid='Test',DivisionAccess=0 where staffid='TEST';
select * from "NetOwnerContactSearch"( 'test.owner',null,null,0, 20);
expect EOF;
update company set divisionid='Test' where companyid='test';
select * from "NetOwnerContactSearch"( 'test.owner',null,null,0, 20);
expect EOF;
select * from "NetOwnerContactSearch"( 'test.owner','testxxxyyyzzz',null,0, 20);
expect EmploymentID=TEST,IsFavourite=0;
insert into favourites (favouritesid, parent, id, staffid, description, type) on existing update defaults off values ('TEST',null,'TEST','TEST','Test Fav','C');
select * from "NetOwnerContactSearch"( 'test.owner','testxxxyyyzzz',null,0, 20);
expect EmploymentID=TEST,IsFavourite=1;
*/
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetOwnerContactSearch" IS
{create PROCEDURE pears."NetOwnerContactSearch"( in "pWebUserID" char(20),in "SearchValue" char(20) default '%',in SearchState char(5) default null,in pSlice integer default 1, in pSliceSize integer default 20 )
result( "EmploymentID" char(20),"Name" char(61),"CompanyName" char(100),address char(60),Jobtitle char(50),"status" char(50),Alert char(255),"IsFavourite" integer )
// IQXWeb
BEGIN
declare x integer;
declare y integer;
declare pStaffID char(20);
set pStaffID = (select first StaffID from iqxnetuser where iqxnetuser.iqxnetuserid = pWebUserID);
set x=pSliceSize;
set y=x*pSlice+1;
set SearchValue = trim(replace(isnull(SearchValue,''),'*',''));
if trim(isnull(SearchState,''))='' then
set SearchState='%';
end if;
select top x start at y
e.employmentid as EmploymentID,
p.forenames + ' ' + p.surname as Name,
c.name as CompanyName,
c.town as address,
e.position as JobTitle,
companystatus.name as status,
c.alert as Alert,
if (select count(*) from favourites where ID=e.employmentid and Staffid=pStaffID) >0 then 1 else 0 endif as IsFavourite
from person p key join employment e key join company c key left outer join companystatus
where
isnull(c.divisionid,'') in (select DivisionID from DashboardStaffDivisions())
and c.status like SearchState
and p.status = 'L'
and SearchValue <> ''
and p.keyname like SearchValue+'%'
order by p.KeyName asc
end
/* DOC
2016-09-19 PC alter routine to allow search, and paging
2017-04-10 PC alter to allow all categories
2018-05-16 GJ Updated to use MHS function to obey divisions & tidied up test
inputs:
pWebUserID
SearchValue
SearchState
pSlice
pSliceSize
outputs:
EmploymentID
Name
CompanyName
address
Jobtitle
status
Alert
IsFavourite
tests:
null pWebUserID
invalid pWebUserID
null SearchValue and pSearchState
create test category
null SearchValue and test pSearchState
incorrect SearchValue and test pSearchState
create three test divisions
check default division
check assigned divisions
check all divisions
check isFavourite
*/
/* TEST
call NetTestSetup('');
update company set divisionid=null where companyid='test';
update person set keyname='testxxxyyyzzz',status='L' where personid='test';
update staff set divisionid=null,DivisionAccess=0 where staffid='TEST';
delete from divisionaccess where staffid='TEST';
delete from favourites where staffid='TEST';
select * from "NetOwnerContactSearch"( null,null,null,0, 20);
expect EOF;
select * from "NetOwnerContactSearch"( 'z99',null,null,0, 20);
expect EOF;
update staff set divisionid='Test',DivisionAccess=0 where staffid='TEST';
select * from "NetOwnerContactSearch"( 'test.owner',null,null,0, 20);
expect EOF;
update company set divisionid='Test' where companyid='test';
select * from "NetOwnerContactSearch"( 'test.owner',null,null,0, 20);
expect EOF;
select * from "NetOwnerContactSearch"( 'test.owner','testxxxyyyzzz',null,0, 20);
expect EmploymentID=TEST,IsFavourite=0;
insert into favourites (favouritesid, parent, id, staffid, description, type) on existing update defaults off values ('TEST',null,'TEST','TEST','Test Fav','C');
select * from "NetOwnerContactSearch"( 'test.owner','testxxxyyyzzz',null,0, 20);
expect EmploymentID=TEST,IsFavourite=1;
*/
}