====== pears.NetTimesheetsForApproval ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetTimesheetsForApproval"( in "pWebUserID" char(20) )
result( "temptimesheetid" char(20),"serialnumber" char(20),"tempname" char(60),"position" char(60),"companyname" char(60),"weekenddate" date,"timesheettype" char(1),"timesheettotal" double,"timesheethours" double,"companyaddress" char(250),"theirref" char(50),
"payrollnumber" char(20),"hasScannedImage" smallint )
// IQXWeb
begin
declare "userClass" char(20);
declare "divid" char(20);
set "userClass" = (select first "iqxnetuserclassid" from "iqxnetuser" where "iqxnetuserid" = "pWebUserID");
if "userClass" = 'OWNER' then
set "divid" = (select first "staff"."divisionid" from "iqxnetuser" key join "staff" where "iqxnetuser"."iqxnetuserid" = "pwebuserid");
select "t"."temptimesheetid","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","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",
(select "sum"("l"."unitspaid") from "temptimesheetline" as "l" key join "temppayband" as "b" where "l"."temptimesheetid" = "t"."temptimesheetid" and "b"."unit" like 'hour%') as "timesheethours",
"NetGetVacancySiteDetails"("vacancy"."vacancyID") as "CompanyAddress",
"t"."theirref","person"."payrollnumber","ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage"
from "temptimesheet" as "t" key join "placement" key join "vacancy" key join "employment" key join "company"
,"temptimesheet" as "t" key join "tempdesk"
,"temptimesheet" as "t" key join "person"
where "t"."estatus" = 3 and "company"."divisionid" = "divid" and "person"."divisionid" = "divid"
order by "t"."serialnumber" desc
else if "userClass" = 'CLIENT' then
select "t"."temptimesheetid","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","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",
(select "sum"("l"."unitscharged") from "temptimesheetline" as "l" key join "temppayband" as "b" where "l"."temptimesheetid" = "t"."temptimesheetid" and "b"."unit" like 'hour%') as "timesheethours",
"NetGetVacancySiteDetails"("vacancy"."vacancyID") as "CompanyAddress","t"."theirref","person"."payrollnumber","ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage"
from "temptimesheet" as "t" key join "placement" key join "vacancy" 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 "t"."estatus" = 3 and "iqxnetuserlink"."iqxnetuserid" = "pwebuserid" and "weekenddate" >= "IQXNetCompanyStartDate"("company"."companyid")
and "NetVacancyRoleAllowed"("pWebUserID","vacancy"."vacancyid",'APPROVETIMESHEETS') = 1
order by "weekenddate" desc,"tempname" asc,"t"."serialnumber" asc
end if
end if
end /* TEST
update temptimesheet set estatus=3 where temptimesheetid='test';
select * from NetTimesheetsForApproval('test.owner');
expect temptimesheetid=TEST,serialnumber=99;
select * from NetTimesheetsForApproval('test.client');
expect temptimesheetid=TEST,serialnumber=99;
update temptimesheet set estatus=0 where temptimesheetid='test';
*/
/* DOC
2018-09-12 PC test routines
2018-11-27 MHS: now respects imageblobid. Made tests pass.
2019-06-12 ET IW-890 now using new function NetGetVacancySiteDetails to get the site address for all user classes. Also updated order by
*/
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetTimesheetsForApproval" IS
{create PROCEDURE pears."NetTimesheetsForApproval"(in pWebUserID char(20))
result(temptimesheetid char(20),serialnumber char(20),tempname char(60),position char(60),companyname char(60),weekenddate date,timesheettype char(1),timesheettotal double,timesheethours double,companyaddress char(250),theirref char(50),
payrollnumber char(20),hasScannedImage smallint )
// IQXWeb
begin
declare userClass char(20);
declare divid char(20);
set userClass=(select first iqxnetuserclassid from iqxnetuser where iqxnetuserid = pWebUserID);
if userClass = 'OWNER' then
set divid=(select first staff.divisionid from iqxnetuser key join staff where iqxnetuser.iqxnetuserid = pwebuserid);
select t.temptimesheetid,t.serialnumber,string(person.surname,', ',person.forenames) as tempname,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,
(select sum(l.unitspaid) from temptimesheetline l key join temppayband b where l.temptimesheetid = t.temptimesheetid and b.unit like 'hour%') as timesheethours,
NetGetVacancySiteDetails(vacancy.vacancyID) as CompanyAddress,
t.theirref, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage
from temptimesheet as t key join placement key join vacancy key join employment key join company
,temptimesheet as t key join tempdesk
,temptimesheet as t key join person
where t.estatus=3 and company.divisionid = divid and person.divisionid = divid order by
t.serialnumber desc
else if userClass = 'CLIENT' then
select t.temptimesheetid,t.serialnumber,string(person.surname,', ',person.forenames) as tempname,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,
(select sum(l.unitscharged) from temptimesheetline l key join temppayband b where l.temptimesheetid = t.temptimesheetid and b.unit like 'hour%') as timesheethours,
NetGetVacancySiteDetails(vacancy.vacancyID) as CompanyAddress,t.theirref, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage
from temptimesheet as t key join placement key join vacancy 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 t.estatus=3 and iqxnetuserlink.iqxnetuserid = pwebuserid and weekenddate >= IQXNetCompanyStartDate(company.companyid)
and NetVacancyRoleAllowed(pWebUserID,vacancy.vacancyid,'APPROVETIMESHEETS') = 1
order by
weekenddate desc,tempname asc,t.serialnumber asc
end if
end if
end
/* TEST
update temptimesheet set estatus=3 where temptimesheetid='test';
select * from NetTimesheetsForApproval('test.owner');
expect temptimesheetid=TEST,serialnumber=99;
select * from NetTimesheetsForApproval('test.client');
expect temptimesheetid=TEST,serialnumber=99;
update temptimesheet set estatus=0 where temptimesheetid='test';
*/
/* DOC
2018-09-12 PC test routines
2018-11-27 MHS: now respects imageblobid. Made tests pass.
2019-06-12 ET IW-890 now using new function NetGetVacancySiteDetails to get the site address for all user classes. Also updated order by
*/
}