====== pears.NetClientShifts ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetClientShifts"(
in "pWebUserID" char(20),
in "pSlice" integer default 0,
in "pSliceSize" integer default 100,
in "pIncCancelled" smallint default 0,
in "pStartDate" char(26) default null,
in "pEndDate" char(26) default null,
in "SearchString" char(100) default null )
result(
"TempShiftPlanID" char(20),
"StartDate" char(20),
"Position" char(50),
"Description" char(50),
"CompanyID" char(20),
"CompanyName" char(60),
"ContactName" char(60),
"Consultant" char(60),
"OurRef" char(50),
"ContractRef" char(20),
"ShiftRef" char(20),
"FilledBy" char(250),
"StartTime" char(15),
"FinishTime" char(15),
"FinishDate" char(30),
"LongDescription" long varchar,
"PersonID" char(20),
"TextStatus" char(100),
"CreatedBy" char(255),
"CancelState" char(50),
"ClientNote" char(50),
"VacancyNotes" long varchar,
"TextStatusFull" char(100),
"SiteDetails" char(300) )
begin
declare "DateRangeStart" date = "isnull"("IQXNetStringToDate"("pStartDate"),"dateadd"("week",-1,current date));
declare "DateRangeEnd" date = "isnull"("IQXNetStringToDate"("pEndDate"),"dateadd"("year",1,current date));
declare "SendVNotesToWeb" char(10) = "isnull"("WPKMaintainGetSwitchValue"('SENDVNOTESTOWEB','WEBSITE','l'),'');
declare "SendVOtherNotesToWeb" char(10) = "isnull"("WPKMaintainGetSwitchValue"('SENDVOTHERNOTESTOWEB','WEBSITE','l'),'');
declare local temporary table "IDs"(
"ID" char(20) not null,
"CompanyStartDate" date null,
) not transactional;
if "IQXNetHasPermission"("pWebUserID",'ORDERJOBS') = 0 then
return
end if;
insert into "IDs"( "ID","CompanyStartDate" )
select distinct "companyid","IQXNetCompanyStartDate"("companyid") from "employment" key join "iqxnetuserlink" where "iqxnetuserid" = "pWebUserID";
select top "pSliceSize" start at("pSliceSize"*"pSlice"+1)
"p"."TempShiftPlanID",
"v"."Position",
"p"."Description",
"Company"."CompanyID",
"Company"."Name" as "CompanyName",
"Pe"."Name" as "ContactName",
"staff"."name" as "Consultant",
"isnull"("s"."referencecode","p"."referencecode") as "OurRef",
"v"."ContractRef",
cast("p"."ShiftSerialNumber" as char(20)) as "ShiftRef",
"string"("pt"."name",(if "pt"."status" = 'A' then ' (S)' endif)) as "FilledBy",
"dateformat"("isnull"("s"."timefrom","p"."TimeFrom"),'hh:mm') as "StartTime",
"dateformat"("isnull"("s"."timeto","p"."TimeTo"),'hh:mm') as "FinishTime",
"isnull"("s"."shiftdate","p"."ShiftDate","v"."startdate") as "StartDate",
(if "FinishTime" < "StartTime" then "dateadd"("dd",1,"StartDate") else "StartDate" endif) as "FinishDate",
(if "SendVOtherNotesToWeb" <> 'Y' then ''
else if "isnull"("d"."showvacextranotes",0) = 1 then cast("v"."extranotes" as long varchar)
else cast("v"."othernotes" as long varchar)
endif
endif) as "LongDescription",
"s"."personid" as "PersonID",
"NetTempShiftStatusString"("s"."state") as "TextStatus",
('Ordered by: '+"p"."orderedby"+' at: '+"dateformat"("p"."whenentered",'dd/mm/yyyy hh:mm')) as "CreatedBy",
"string"("dateformat"("s"."WhenCancelled",'dd/mm/yyyy hh:nn:ss'),' by ',"isnull"((select "name" from "staff" where "staff"."staffid" = "s"."WhoCancelled"),'(not recorded)')) as "CancelState",
"p"."ClientNote",
(if "SendVNotesToWeb" = 'Y' then "v"."notes" else null endif) as "VacancyNotes",
"NetTempShiftStatusString"("s"."state","s"."tempconfirmed","s"."clientconfirmed","cr"."name") as "TextStatusFull",
"isnull"(
"string"(
"v"."sitename",
(if "isnull"("v"."addr1",'') <> '' then
(if "v"."Sitename" <> '' then
', '
endif)
+"v"."addr1"
endif),
(if "isnull"("v"."addr2",'') <> '' then
', '+"v"."addr2"
endif),
(if "isnull"("v"."addr3",'') <> '' then
', '+"v"."addr3"
endif),
(if "isnull"("v"."Town",'') <> '' then
', '+"v"."town"
endif),
(if "isnull"("v"."postcode",'') <> '' then
', '+"v"."postcode"
endif)),
"GetCompanyAddressOnLine"("e"."companyid")) as "SiteDetails"
from "TempShiftplan" as "p"
key left outer join "tempshift" as "s"
,"TempShiftplan" as "p"
key join "vacancy" as "v"
key join "tempdesk" as "td"
key join "Employment" as "e"
key join("Company","Person" as "Pe")
join "IDs" on "e"."CompanyID" = "IDs"."ID"
,"vacancy" as "v"
key join "Department" as "d"
,"vacancy" as "v"
key left outer join "Staff"
,"tempshift" as "s"
key left outer join "person" as "pt"
,"tempshift" as "s"
key left outer join "tempshiftcancelreason" as "cr"
where "StartDate" between "DateRangeStart" and "DateRangeEnd"
and "td"."desktype" = 'S'
and "StartDate" >= "IDs"."CompanyStartDate"
and("pIncCancelled" = 0 and not("isnull"("s"."State",'') = 'C' and "isnull"("s"."cRefill",0) = 0)
or "pIncCancelled" = 1)
order by "StartDate" desc,"p"."TempShiftPlanID" desc
end /* DOC
2020-07-01 ET Created based on NetClientRequirmentList modified to only include shifts
*/
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetClientShifts" IS
{create PROCEDURE pears."NetClientShifts"(
IN pWebUserID char(20),
IN pSlice integer default 0,
IN pSliceSize integer default 100,
IN pIncCancelled smallint default 0,
IN pStartDate char(26) default null,
IN pEndDate char(26) default null,
IN SearchString char(100) default null
)
RESULT(
TempShiftPlanID char(20),
StartDate char(20),
Position char(50),
Description char(50),
CompanyID char(20),
CompanyName char(60),
ContactName char(60),
Consultant char(60),
OurRef char(50),
ContractRef char(20),
ShiftRef char(20),
FilledBy char(250),
StartTime char(15),
FinishTime char(15),
FinishDate char(30),
LongDescription long varchar,
PersonID char(20),
TextStatus char(100),
CreatedBy char(255),
CancelState char(50),
ClientNote char(50),
VacancyNotes long varchar,
TextStatusFull char(100),
SiteDetails char(300)
)
BEGIN
DECLARE DateRangeStart DATE = isnull(IQXNetStringToDate(pStartDate),dateadd(week,-1,CURRENT DATE));
DECLARE DateRangeEnd DATE = isnull(IQXNetStringToDate(pEndDate),dateadd(year,1,CURRENT DATE));
DECLARE SendVNotesToWeb char(10) = isnull(WPKMaintainGetSwitchValue('SENDVNOTESTOWEB','WEBSITE','l'),'');
DECLARE SendVOtherNotesToWeb char(10) = isnull(WPKMaintainGetSwitchValue('SENDVOTHERNOTESTOWEB','WEBSITE','l'),'');
DECLARE LOCAL TEMPORARY TABLE IDs(
ID char(20) not null,
CompanyStartDate date null,
) NOT TRANSACTIONAL;
IF IQXNetHasPermission(pWebUserID,'ORDERJOBS') = 0 THEN
RETURN
END IF;
INSERT INTO IDs( ID,CompanyStartDate )
SELECT DISTINCT companyid,IQXNetCompanyStartDate(companyid) FROM employment KEY JOIN iqxnetuserlink WHERE iqxnetuserid = pWebUserID;
SELECT TOP pSliceSize START AT (pSliceSize*pSlice+1)
p.TempShiftPlanID,
v.Position,
p.Description,
Company.CompanyID,
Company.Name AS CompanyName,
Pe.Name AS ContactName,
staff.name AS Consultant,
isnull(s.referencecode,p.referencecode) AS OurRef,
v.ContractRef,
cast(p.ShiftSerialNumber AS char(20)) AS ShiftRef,
string(pt.name,(IF pt.status = 'A' THEN ' (S)' END IF)) AS FilledBy,
dateformat(isnull(s.timefrom,p.TimeFrom),'hh:mm') AS StartTime,
dateformat(isnull(s.timeto,p.TimeTo),'hh:mm') AS FinishTime,
isnull(s.shiftdate,p.ShiftDate,v.startdate) AS StartDate,
(IF FinishTime < StartTime THEN dateadd(dd,1,StartDate) ELSE StartDate END IF) AS FinishDate,
(IF SendVOtherNotesToWeb <> 'Y' THEN ''
ELSE IF isnull(d.showvacextranotes,0) = 1 THEN cast(v.extranotes AS long varchar)
ELSE cast(v.othernotes AS long varchar)
END IF
END IF) AS LongDescription,
s.personid AS PersonID,
NetTempShiftStatusString(s.state) AS TextStatus,
('Ordered by: '+p.orderedby+' at: '+dateformat(p.whenentered,'dd/mm/yyyy hh:mm')) AS CreatedBy,
string(dateformat(s.WhenCancelled,'dd/mm/yyyy hh:nn:ss'),' by ',isnull((SELECT name FROM staff WHERE staff.staffid = s.WhoCancelled),'(not recorded)')) AS CancelState,
p.ClientNote,
(IF SendVNotesToWeb = 'Y' THEN v.notes ELSE null END IF) AS VacancyNotes,
NetTempShiftStatusString(s.state,s.tempconfirmed,s.clientconfirmed,cr.name) AS TextStatusFull,
isnull(
string(
v.sitename,
(IF isnull(v.addr1,'') <> '' THEN
(IF v.Sitename <> '' then
', '
END IF)
+v.addr1
END IF),
(IF isnull(v.addr2,'') <> '' THEN
', '+v.addr2
END IF),
(IF isnull(v.addr3,'') <> '' THEN
', '+v.addr3
END IF),
(IF isnull(v.Town,'') <> '' THEN
', '+v.town
END IF),
(IF isnull(v.postcode,'') <> '' THEN
', '+v.postcode
END IF)
),
GetCompanyAddressOnLine(e.companyid)
) AS SiteDetails
FROM
TempShiftplan AS p
KEY LEFT OUTER JOIN tempshift AS s,
TempShiftplan AS p
key join vacancy AS v
key join tempdesk AS td
key join Employment AS e
key join(Company,Person AS Pe)
join IDs on e.CompanyID = IDs.ID,
vacancy AS v
key join Department AS d,
vacancy AS v
key left outer join Staff,
tempshift AS s
key left outer join person AS pt,
tempshift AS s
key left outer join tempshiftcancelreason AS cr
WHERE
StartDate BETWEEN DateRangeStart AND DateRangeEnd
AND td.desktype = 'S'
AND StartDate >= IDs.CompanyStartDate
AND (
pIncCancelled = 0 AND NOT (isnull(s.State,'') = 'C' AND isnull(s.cRefill,0) = 0)
OR
pIncCancelled = 1
)
ORDER BY StartDate DESC, p.TempShiftPlanID DESC
END
/* DOC
2020-07-01 ET Created based on NetClientRequirmentList modified to only include shifts
*/
}