====== pears.NetTimesheets ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetTimesheets"( in "pWebUserID" char(20),in "pSlice" integer default 0,in "pSliceSize" integer default 20,in "pStartDate" char(20) default null,in "pEndDate" char(20) default null )
result( "temptimesheetid" char(20),"serialnumber" char(20),"tempname" char(60),"position" char(60),"companyname" char(60),"weekenddate" date,"timesheettype" char(1),"timesheettotal" double,"companyaddress" char(250),"theirref" char(50),"payrollnumber" char(20),"hasScannedImage" smallint,"awaitsApproval" smallint )
// IQXWeb
begin
declare "userClass" char(20);
declare "x" integer;
declare "y" integer;
declare @companycount integer;
declare "DateRangeStart" date;
declare "DateRangeEnd" date;
declare "divid" char(20);
set "x" = "pSliceSize";
set "y" = "x"*"pSlice"+1;
set "userClass" = (select first "iqxnetuserclassid" from "iqxnetuser" where "iqxnetuserid" = "pWebUserID");
set "DateRangeStart" = "isnull"("pStartDate","dateadd"("yy",-10,"now"()));
set "DateRangeEnd" = "isnull"("pEndDate","dateadd"("yy",1,"now"()));
if "userClass" = 'CANDIDATE' then
select top "x" start at "y" "t"."temptimesheetid","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","isnull"("employment"."position","vacancy"."position"),"company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
if "tempdesk"."desktype" = 'S' then 'S' else if "tempdesk"."desktype" = 'W'
and exists(select * from "placement" where "placementid" = "t"."placementid" and "worknormalhours" is not null and "workstarttime" is not null
and("isnull"("workmonday",0) = 1 or "isnull"("worktuesday",0) = 1 or "isnull"("workwednesday",0) = 1 or "isnull"("workthursday",0) = 1 or "isnull"("workfriday",0) = 1
or "isnull"("worksaturday",0) = 1 or "isnull"("worksunday",0) = 1)) then 'T'
else 'C'
endif endif as "timesheettype",
(select "sum"("unitspaid"*"payrate") from "temptimesheetline" where "temptimesheetid" = "t"."temptimesheetid") as "timesheettotal",
"NetGetVacancySiteDetails"("vacancy"."vacancyID") as "CompanyAddress",
"t"."theirref","person"."payrollnumber","ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage",
(if "t"."estatus" = 3 then 1 else 0 endif) as "awaitsApproval"
from "temptimesheet" as "t" key join "placement" key join "vacancy","placement" key join "employment" key join "company"
,"temptimesheet" as "t" key join "tempdesk"
,"temptimesheet" as "t" key join "person" key join "iqxnetuserlink"
where "weekenddate" between "DateRangeStart" and "DateRangeEnd" and "iqxnetuserlink"."iqxnetuserid" = "pwebuserid"
order by "weekenddate" desc,"companyname" asc,"t"."serialnumber" asc
else if "userClass" = 'AGENCY' then
select distinct top "x" start at "y" "t"."temptimesheetid","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","isnull"("employment"."position","vacancy"."position"),"company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
if "tempdesk"."desktype" = 'S' then 'S' else if "tempdesk"."desktype" = 'W'
and exists(select * from "placement" where "placementid" = "t"."placementid" and "worknormalhours" is not null and "workstarttime" is not null
and("isnull"("workmonday",0) = 1 or "isnull"("worktuesday",0) = 1 or "isnull"("workwednesday",0) = 1 or "isnull"("workthursday",0) = 1 or "isnull"("workfriday",0) = 1
or "isnull"("worksaturday",0) = 1 or "isnull"("worksunday",0) = 1)) then 'T'
else 'C'
endif endif as "timesheettype",
(select "sum"("unitspaid"*"payrate") from "temptimesheetline" where "temptimesheetid" = "t"."temptimesheetid") as "timesheettotal",
"NetGetVacancySiteDetails"("vacancy"."vacancyID") as "CompanyAddress",
"t"."theirref","person"."payrollnumber","ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage",
(if "t"."estatus" = 3 then 1 else 0 endif) as "awaitsApproval"
from "temptimesheet" as "t" key join "placement" key join "vacancy","placement" key join "employment" key join "company"
,"temptimesheet" as "t" key join "tempdesk"
,"temptimesheet" as "t" key join "person" key join "pay_employee" key join "company" as "agcomp" key join "employment" as "agemp" key join "iqxnetuserlink"
where "weekenddate" between "DateRangeStart" and "DateRangeEnd" and "iqxnetuserlink"."iqxnetuserid" = "pwebuserid" and "weekenddate" >= "IQXNetCompanyStartDate"("agcomp"."companyid")
order by "weekenddate" desc,"tempname" asc,"t"."serialnumber" asc
else if "userClass" = 'OWNER' then
set "divid" = (select first "staff"."divisionid" from "iqxnetuser" key join "staff" where "iqxnetuser"."iqxnetuserid" = "pwebuserid");
select distinct top "x" start at "y" "t"."temptimesheetid","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","isnull"("employment"."position","vacancy"."position"),"company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
if "tempdesk"."desktype" = 'S' then 'S' else if "tempdesk"."desktype" = 'W'
and exists(select * from "placement" where "placementid" = "t"."placementid" and "worknormalhours" is not null and "workstarttime" is not null
and("isnull"("workmonday",0) = 1 or "isnull"("worktuesday",0) = 1 or "isnull"("workwednesday",0) = 1 or "isnull"("workthursday",0) = 1 or "isnull"("workfriday",0) = 1
or "isnull"("worksaturday",0) = 1 or "isnull"("worksunday",0) = 1)) then 'T'
else 'C'
endif endif as "timesheettype",
(select "sum"("unitspaid"*"payrate") from "temptimesheetline" where "temptimesheetid" = "t"."temptimesheetid") as "timesheettotal",
"NetGetVacancySiteDetails"("vacancy"."vacancyID") as "CompanyAddress",
"t"."theirref","person"."payrollnumber","ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage",
(if "t"."estatus" = 3 then 1 else 0 endif) as "awaitsApproval"
from "temptimesheet" as "t" key join "placement" key join "vacancy","placement" key join "employment" key join "company"
,"temptimesheet" as "t" key join "tempdesk"
,"temptimesheet" as "t" key join "person"
where "weekenddate" between "DateRangeStart" and "DateRangeEnd" and "company"."divisionid" = "divid" and "person"."divisionid" = "divid"
order by "weekenddate" desc,"t"."serialnumber" desc
else -- CLIENT
select distinct top "x" start at "y" "t"."temptimesheetid","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","isnull"("employment"."position","vacancy"."position"),"company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
if "tempdesk"."desktype" = 'S' then 'S' else if "tempdesk"."desktype" = 'W'
and exists(select * from "placement" where "placementid" = "t"."placementid" and "worknormalhours" is not null and "workstarttime" is not null
and("isnull"("workmonday",0) = 1 or "isnull"("worktuesday",0) = 1 or "isnull"("workwednesday",0) = 1 or "isnull"("workthursday",0) = 1 or "isnull"("workfriday",0) = 1
or "isnull"("worksaturday",0) = 1 or "isnull"("worksunday",0) = 1)) then 'T'
else 'C'
endif endif as "timesheettype",
(select "sum"("unitscharged"*"chargerate") from "temptimesheetline" where "temptimesheetid" = "t"."temptimesheetid") as "timesheettotal",
"NetGetVacancySiteDetails"("vacancy"."vacancyID") as "CompanyAddress","t"."theirref","person"."payrollnumber","ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage",(if "t"."estatus" = 3 then 1 else 0 endif) as "awaitsApproval"
from "temptimesheet" as "t"
key join "placement"
key join "vacancy"
,"placement"
key join "employment"
key join "company"
key join "employment" as "allemps"
key join "iqxnetuserlink"
,"temptimesheet" as "t"
key join "tempdesk"
,"temptimesheet" as "t"
key join "person"
where "weekenddate" between "DateRangeStart" and "DateRangeEnd" and "iqxnetuserlink"."iqxnetuserid" = "pwebuserid" and "weekenddate" >= "IQXNetCompanyStartDate"("company"."companyid")
order by "weekenddate" desc,"tempname" asc,"t"."serialnumber" asc
end if
end if
end if
end /* DOC
2017-11-15 PC IW-311 position is drawn from the employment then the vacancy
2018-02-06 PC add date parameters
2018-09-11 PC test routines and declare divid
2018-11-27 MHS: now respects imageblobid.
2019-06-12 ET IW-890 now using new function NetGetVacancySiteDetails to get the site address for all user classes. Also updated order by.
*/
/* TEST
select * from NetTimesheets('test.candidate',0,10,null,null);
expect temptimesheetid=TEST,serialnumber=99;
*/
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetTimesheets" IS
{create PROCEDURE pears."NetTimesheets"(in pWebUserID char(20),in pSlice integer default 0,in pSliceSize integer default 20, in pStartDate char(20) default null,in pEndDate char(20) default null)
result(temptimesheetid char(20),serialnumber char(20),tempname char(60),position char(60),companyname char(60),weekenddate date,timesheettype char(1),timesheettotal double,companyaddress char(250),theirref char(50), payrollnumber char(20), hasScannedImage smallint, awaitsApproval smallint)
// IQXWeb
begin
declare userClass char(20);
declare x integer;
declare y integer;
declare @companycount integer;
declare DateRangeStart date;
declare DateRangeEnd date;
declare divid char(20);
set x=pSliceSize;
set y=x*pSlice+1;
set userClass=(select first iqxnetuserclassid from iqxnetuser where iqxnetuserid = pWebUserID);
set DateRangeStart=isnull(pStartDate,dateadd(yy,-10,now(*)));
set DateRangeEnd=isnull(pEndDate,dateadd(yy,1,now(*)));
if userClass = 'CANDIDATE' then
select top x start at y t.temptimesheetid,t.serialnumber,string(person.surname,', ',person.forenames) as tempname,isnull(employment.position,vacancy.position),company.name as companyname,weekmonthenddate(t.period,t.periodlength) as weekenddate,
if tempdesk.desktype = 'S' then 'S' else if tempdesk.desktype = 'W'
and exists(select * from placement where placementid = t.placementid and worknormalhours is not null and workstarttime is not null
and(isnull(workmonday,0) = 1 or isnull(worktuesday,0) = 1 or isnull(workwednesday,0) = 1 or isnull(workthursday,0) = 1 or isnull(workfriday,0) = 1
or isnull(worksaturday,0) = 1 or isnull(worksunday,0) = 1)) then 'T'
else 'C'
endif
endif as timesheettype,
(select sum(unitspaid*payrate) from temptimesheetline where temptimesheetid = t.temptimesheetid) as timesheettotal,
NetGetVacancySiteDetails(vacancy.vacancyID) as CompanyAddress,
t.theirref, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage,
(if t.estatus=3 then 1 else 0 endif) as awaitsApproval
from temptimesheet as t key join placement key join vacancy,placement key join employment key join company
,temptimesheet as t key join tempdesk
,temptimesheet as t key join person key join iqxnetuserlink
where weekenddate between DateRangeStart and DateRangeEnd and iqxnetuserlink.iqxnetuserid = pwebuserid
order by
weekenddate desc,companyname asc,t.serialnumber asc
else if userClass = 'AGENCY' then
select distinct top x start at y t.temptimesheetid,t.serialnumber,string(person.surname,', ',person.forenames) as tempname,isnull(employment.position,vacancy.position),company.name as companyname,weekmonthenddate(t.period,t.periodlength) as weekenddate,
if tempdesk.desktype = 'S' then 'S' else if tempdesk.desktype = 'W'
and exists(select * from placement where placementid = t.placementid and worknormalhours is not null and workstarttime is not null
and(isnull(workmonday,0) = 1 or isnull(worktuesday,0) = 1 or isnull(workwednesday,0) = 1 or isnull(workthursday,0) = 1 or isnull(workfriday,0) = 1
or isnull(worksaturday,0) = 1 or isnull(worksunday,0) = 1)) then 'T'
else 'C'
endif
endif as timesheettype,
(select sum(unitspaid*payrate) from temptimesheetline where temptimesheetid = t.temptimesheetid) as timesheettotal,
NetGetVacancySiteDetails(vacancy.vacancyID) as CompanyAddress,
t.theirref, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage,
(if t.estatus=3 then 1 else 0 endif) as awaitsApproval
from temptimesheet as t key join placement key join vacancy, placement key join employment key join company
,temptimesheet as t key join tempdesk
,temptimesheet as t key join person key join pay_employee key join company as agcomp key join employment as agemp key join iqxnetuserlink
where weekenddate between DateRangeStart and DateRangeEnd and iqxnetuserlink.iqxnetuserid = pwebuserid and weekenddate >= IQXNetCompanyStartDate(agcomp.companyid)
order by
weekenddate desc,tempname asc,t.serialnumber asc
else if userClass = 'OWNER' then
set divid=(select first staff.divisionid from iqxnetuser key join staff where iqxnetuser.iqxnetuserid = pwebuserid);
select distinct top x start at y t.temptimesheetid,t.serialnumber,string(person.surname,', ',person.forenames) as tempname,isnull(employment.position,vacancy.position),company.name as companyname,weekmonthenddate(t.period,t.periodlength) as weekenddate,
if tempdesk.desktype = 'S' then 'S' else if tempdesk.desktype = 'W'
and exists(select * from placement where placementid = t.placementid and worknormalhours is not null and workstarttime is not null
and(isnull(workmonday,0) = 1 or isnull(worktuesday,0) = 1 or isnull(workwednesday,0) = 1 or isnull(workthursday,0) = 1 or isnull(workfriday,0) = 1
or isnull(worksaturday,0) = 1 or isnull(worksunday,0) = 1)) then 'T'
else 'C'
endif
endif as timesheettype,
(select sum(unitspaid*payrate) from temptimesheetline where temptimesheetid = t.temptimesheetid) as timesheettotal,
NetGetVacancySiteDetails(vacancy.vacancyID) as CompanyAddress,
t.theirref, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage,
(if t.estatus=3 then 1 else 0 endif) as awaitsApproval
from temptimesheet as t key join placement key join vacancy,placement key join employment key join company
,temptimesheet as t key join tempdesk
,temptimesheet as t key join person
where weekenddate between DateRangeStart and DateRangeEnd and company.divisionid = divid and person.divisionid = divid order by
weekenddate desc,t.serialnumber desc
else -- CLIENT
select distinct top x start at y t.temptimesheetid,t.serialnumber,string(person.surname,', ',person.forenames) as tempname,isnull(employment.position,vacancy.position),company.name as companyname,weekmonthenddate(t.period,t.periodlength) as weekenddate,
if tempdesk.desktype = 'S' then 'S' else if tempdesk.desktype = 'W'
and exists(select * from placement where placementid = t.placementid and worknormalhours is not null and workstarttime is not null
and(isnull(workmonday,0) = 1 or isnull(worktuesday,0) = 1 or isnull(workwednesday,0) = 1 or isnull(workthursday,0) = 1 or isnull(workfriday,0) = 1
or isnull(worksaturday,0) = 1 or isnull(worksunday,0) = 1)) then 'T'
else 'C'
endif
endif as timesheettype,(select sum(unitscharged*chargerate) from temptimesheetline where temptimesheetid = t.temptimesheetid) as timesheettotal,
NetGetVacancySiteDetails(vacancy.vacancyID) as CompanyAddress,t.theirref, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage, (if t.estatus=3 then 1 else 0 endif) as awaitsApproval
from
temptimesheet as t
key join placement
key join vacancy,
placement
key join employment
key join company
key join employment as allemps
key join iqxnetuserlink,
temptimesheet as t
key join tempdesk,
temptimesheet as t
key join person
where weekenddate between DateRangeStart and DateRangeEnd and iqxnetuserlink.iqxnetuserid = pwebuserid and weekenddate >= IQXNetCompanyStartDate(company.companyid)
order by
weekenddate desc,tempname asc,t.serialnumber asc
end if
end if
end if
end
/* DOC
2017-11-15 PC IW-311 position is drawn from the employment then the vacancy
2018-02-06 PC add date parameters
2018-09-11 PC test routines and declare divid
2018-11-27 MHS: now respects imageblobid.
2019-06-12 ET IW-890 now using new function NetGetVacancySiteDetails to get the site address for all user classes. Also updated order by.
*/
/* TEST
select * from NetTimesheets('test.candidate',0,10,null,null);
expect temptimesheetid=TEST,serialnumber=99;
*/
}