====== pears.NetReportTimesheetsExpanded ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."NetReportTimesheetsExpanded"( in "pWebUserID" char(20),in "From__D" char(20),in "To__D" char(20) )
result( "Title__H" char(100),"Number__1" char(20),"Temp" char(60),"Position" char(60),"Client__B" char(100),"End_Date__DXA" date,"Pay_Type" char(100),"Unit" char(100),"Units__R" double,"Rate__MR" double,"Total__MR" double )
begin
declare "pstart" date;
declare "pend" date;
declare "pStartPeriod" integer;
declare "pEndPeriod" integer;
declare "rTitle" char(100);
declare "userClass" char(20);
declare local temporary table "IDs"(
"ID" char(20) null,
) not transactional;set "pstart" = "iqxnetstringtodate"("From__D");
set "pend" = "iqxnetstringtodate"("To__D");
set "rTitle" = "dateformat"("pstart",'dd/mm/yyyy')+' - '+"dateformat"("pend",'dd/mm/yyyy');
set "pStartPeriod" = "weekcontaining"("pstart");
set "pEndPeriod" = "weekcontaining"("pend");
set "userClass" = (select first "iqxnetuserclassid" from "iqxnetuser" where "iqxnetuserid" = "pWebUserID");
if "userClass" = 'CANDIDATE' then
insert into "IDs"( "ID" )
select distinct "personid" from "iqxnetuserlink" where "iqxnetuserid" = "pWebUserID";
select "rTitle","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","vacancy"."position","company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
"b"."description",
"tl"."unitspaid",
"tl"."payrate",
"tl"."unitspaid"*"tl"."payrate"
from "temppayband" as "b" key join "temptimesheetline" as "tl" key join "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"."personid" = any(select "id" from "ids")
and "t"."Period" between "pStartPeriod" and "pEndPeriod"
and "t"."PeriodLength" = 'W'
group by grouping sets((),("weekenddate"),(("weekenddate"),"rTitle","t"."serialnumber","tempname","vacancy"."position","companyname","b"."description","tl"."unitspaid","tl"."payrate"))
else if "userClass" = 'AGENCY' then
insert into "IDs"( "ID" )
select distinct "e"."companyid" from "iqxnetuserlink" as "l" key join "employment" as "e" where "l"."iqxnetuserid" = "pWebUserID";
select "rTitle","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","vacancy"."position","company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
"b"."description",
"tl"."unitspaid",
"tl"."payrate",
"tl"."unitspaid"*"tl"."payrate"
from "temppayband" as "b" key join "temptimesheetline" as "tl" key join "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" key join "pay_employee" key join "company" as "agcomp"
where "agcomp"."companyid" = any(select "id" from "ids")
and "weekenddate" >= "IQXNetCompanyStartDate"("agcomp"."companyid")
and "t"."Period" between "pStartPeriod" and "pEndPeriod"
and "t"."PeriodLength" = 'W'
group by grouping sets((),("weekenddate"),(("weekenddate"),"rTitle","t"."serialnumber","tempname","vacancy"."position","companyname","b"."description","tl"."unitspaid","tl"."payrate"))
else -- CLIENT
insert into "IDs"( "ID" )
select distinct "e"."companyid" from "iqxnetuserlink" as "l" key join "employment" as "e" where "l"."iqxnetuserid" = "pWebUserID";
select "rTitle","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","vacancy"."position","company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
"b"."description",
"tl"."unitscharged",
"tl"."chargerate",
"tl"."unitscharged"*"tl"."chargerate"
from "temppayband" as "b" key join "temptimesheetline" as "tl" key join "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 "company"."companyid" = any(select "id" from "ids")
and "weekenddate" >= "IQXNetCompanyStartDate"("company"."companyid")
and "t"."Period" between "pStartPeriod" and "pEndPeriod"
and "t"."PeriodLength" = 'W'
group by grouping sets((),("weekenddate"),(("weekenddate"),"t"."serialnumber","tempname","vacancy"."position","companyname","t"."temptimesheetid","b"."description","tl"."unitspaid","tl"."payrate"))
end if
end if
end
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetReportTimesheetsExpanded" IS
{create procedure pears."NetReportTimesheetsExpanded"( in "pWebUserID" char(20),in "From__D" char(20),in "To__D" char(20) )
result( "Title__H" char(100),"Number__1" char(20),"Temp" char(60),"Position" char(60),"Client__B" char(100),"End_Date__DXA" date,"Pay_Type" char(100),"Unit" char(100),"Units__R" double,"Rate__MR" double,"Total__MR" double )
begin
declare "pstart" date;
declare "pend" date;
declare "pStartPeriod" integer;
declare "pEndPeriod" integer;
declare "rTitle" char(100);
declare "userClass" char(20);
declare local temporary table "IDs"(
"ID" char(20) null,
) not transactional;set "pstart" = "iqxnetstringtodate"("From__D");
set "pend" = "iqxnetstringtodate"("To__D");
set "rTitle" = "dateformat"("pstart",'dd/mm/yyyy')+' - '+"dateformat"("pend",'dd/mm/yyyy');
set "pStartPeriod" = "weekcontaining"("pstart");
set "pEndPeriod" = "weekcontaining"("pend");
set "userClass" = (select first "iqxnetuserclassid" from "iqxnetuser" where "iqxnetuserid" = "pWebUserID");
if "userClass" = 'CANDIDATE' then
insert into "IDs"( "ID" )
select distinct "personid" from "iqxnetuserlink" where "iqxnetuserid" = "pWebUserID";
select "rTitle","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","vacancy"."position","company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
"b"."description",
"tl"."unitspaid",
"tl"."payrate",
"tl"."unitspaid"*"tl"."payrate"
from "temppayband" as "b" key join "temptimesheetline" as "tl" key join "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"."personid" = any(select "id" from "ids")
and "t"."Period" between "pStartPeriod" and "pEndPeriod"
and "t"."PeriodLength" = 'W'
group by grouping sets((),("weekenddate"),(("weekenddate"),"rTitle","t"."serialnumber","tempname","vacancy"."position","companyname","b"."description","tl"."unitspaid","tl"."payrate"))
else if "userClass" = 'AGENCY' then
insert into "IDs"( "ID" )
select distinct "e"."companyid" from "iqxnetuserlink" as "l" key join "employment" as "e" where "l"."iqxnetuserid" = "pWebUserID";
select "rTitle","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","vacancy"."position","company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
"b"."description",
"tl"."unitspaid",
"tl"."payrate",
"tl"."unitspaid"*"tl"."payrate"
from "temppayband" as "b" key join "temptimesheetline" as "tl" key join "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" key join "pay_employee" key join "company" as "agcomp"
where "agcomp"."companyid" = any(select "id" from "ids")
and "weekenddate" >= "IQXNetCompanyStartDate"("agcomp"."companyid")
and "t"."Period" between "pStartPeriod" and "pEndPeriod"
and "t"."PeriodLength" = 'W'
group by grouping sets((),("weekenddate"),(("weekenddate"),"rTitle","t"."serialnumber","tempname","vacancy"."position","companyname","b"."description","tl"."unitspaid","tl"."payrate"))
else -- CLIENT
insert into "IDs"( "ID" )
select distinct "e"."companyid" from "iqxnetuserlink" as "l" key join "employment" as "e" where "l"."iqxnetuserid" = "pWebUserID";
select "rTitle","t"."serialnumber","string"("person"."surname",', ',"person"."forenames") as "tempname","vacancy"."position","company"."name" as "companyname","weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate",
"b"."description",
"tl"."unitscharged",
"tl"."chargerate",
"tl"."unitscharged"*"tl"."chargerate"
from "temppayband" as "b" key join "temptimesheetline" as "tl" key join "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 "company"."companyid" = any(select "id" from "ids")
and "weekenddate" >= "IQXNetCompanyStartDate"("company"."companyid")
and "t"."Period" between "pStartPeriod" and "pEndPeriod"
and "t"."PeriodLength" = 'W'
group by grouping sets((),("weekenddate"),(("weekenddate"),"t"."serialnumber","tempname","vacancy"."position","companyname","t"."temptimesheetid","b"."description","tl"."unitspaid","tl"."payrate"))
end if
end if
end
}