====== pears.NetTimesheet ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create procedure "pears"."NetTimesheet"( in "pWebUserID" char(20),in "pTempTimesheetID" char(20) ) result( "temptimesheetid" char(20),"serialnumber" char(20),"timesheettype" char(1),"tempname" char(60),"position" char(60),"companyname" char(60),"weekenddate" date,"completedby" char(50),"completedat" "datetime","companyaddress" char(250),"payrollnumber" char(20),"hasScannedImage" smallint,"TSPeriod" integer,"WeekEndingDate" char(10),"OrderedBy" char(250) ) // IQXWeb begin select "t"."temptimesheetid","t"."serialnumber", if "tempdesk"."desktype" = 'S' or "tempdesk"."ShiftsOnContractTimesheet" = 1 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", "string"("person"."surname",', ',"person"."forenames") as "tempname", "isnull"("employment"."position","vacancy"."position"), "company"."name" as "companyname", "weekmonthenddate"("t"."period","t"."periodlength") as "weekenddate", "isnull"((select first "i"."name" from "tempprovtimesheethistory" as "h" join "iqxnetuser" as "i" on "h"."externaluserid" = "i"."iqxnetuserid" where "h"."temptimesheetid" = "t"."temptimesheetid" and "h"."newstatus" = 100),(select top 1 "s"."name" from "tempprovtimesheethistory" as "h" left outer join "staff" as "s" on "h"."staffid" = "s"."staffid" where "h"."temptimesheetid" = "t"."temptimesheetid" and "h"."newstatus" = 100)) as "completedby", "isnull"((select first "h"."whenentered" from "tempprovtimesheethistory" as "h" join "iqxnetuser" as "i" on "h"."externaluserid" = "i"."iqxnetuserid" where "h"."temptimesheetid" = "t"."temptimesheetid" and "h"."newstatus" = 100 order by "whenentered" desc),(select top 1 "h"."whenentered" from "tempprovtimesheethistory" as "h" left outer join "staff" as "s" on "h"."staffid" = "s"."staffid" where "h"."temptimesheetid" = "t"."temptimesheetid" and "h"."newstatus" = 100 order by "whenentered" desc),null) as "completedat", "NetGetVacancySiteDetails"("vacancy"."vacancyID") as "companyaddress","person"."payrollnumber", "ifnull"("nullif"("string"("t"."imageblobid","t"."ScanPathFileName"),''),0,1) as "hasScannedImage", "period", "dateformat"("weekenddate"("round"("period"/100,0),"period"-("round"("period"/100,0))*100),'yyyy-mm-dd'), "isnull"((select "list"(distinct "orderedby") from "tempshiftplan" as "pl" key join "tempshift" key join "temptimesheet" as "ts" where "ts"."temptimesheetid" = "t"."temptimesheetid"),'N/R') as "OrderedByList" 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 "t"."temptimesheetid" = "ptemptimesheetid" and "nethaspermission"("pWebUserID","person"."personid","company"."companyid") = 1 end /* DOC 2017-04-11 PC IW-204 Period added 2017-04-26 PC IW-204 week ending date added 2017-06-22 PC Test and doc 2017-10-23 PC ASA-12 RC2 2017-10-27 PC ASA-11 Person who ordered shift 2017-11-15 PC IW-311 position is drawn from the employment, then the vacancy 2018-04-30 PC modify to over-ride default work pattern where shifts are present 2018-05-29 MHS IW-553 Make it obey tempdesk.ShiftsOnContractTimesheet rather than the presence of shifts. Simplify tests and make pass. 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 */ /* TEST call NetTestSetup(''); insert into temptimesheet (temptimesheetid,placementid,period,periodlength,serialnumber,tempdeskid,personid) on existing update defaults off values ('TEST','TEST',weekcontaining(now(*)),'W',99,'test','TEST'); select serialnumber from NetTimesheet('test.candidate','TEST'); expect serialnumber=99; */ go COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetTimesheet" IS {create PROCEDURE pears."NetTimesheet"(in pWebUserID char(20),in pTempTimesheetID char(20)) result(temptimesheetid char(20),serialnumber char(20),timesheettype char(1),tempname char(60),position char(60),companyname char(60),weekenddate date,completedby char(50),completedat datetime, companyaddress char(250), payrollnumber char(20), hasScannedImage smallint, TSPeriod integer,WeekEndingDate char(10),OrderedBy char(250)) // IQXWeb begin select t.temptimesheetid,t.serialnumber, if tempdesk.desktype = 'S' or tempdesk.ShiftsOnContractTimesheet = 1 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, string(person.surname,', ',person.forenames) as tempname, isnull(employment.position,vacancy.position), company.name as companyname, weekmonthenddate(t.period,t.periodlength) as weekenddate, isnull((select first i.name from tempprovtimesheethistory as h join iqxnetuser as i on h.externaluserid = i.iqxnetuserid where h.temptimesheetid = t.temptimesheetid and h.newstatus = 100),(select top 1 s.name from tempprovtimesheethistory h left outer join staff s on h.staffid=s.staffid where h.temptimesheetid = t.temptimesheetid and h.newstatus = 100)) as completedby, isnull((select first h.whenentered from tempprovtimesheethistory as h join iqxnetuser as i on h.externaluserid = i.iqxnetuserid where h.temptimesheetid = t.temptimesheetid and h.newstatus = 100 order by whenentered desc),(select top 1 h.whenentered from tempprovtimesheethistory h left outer join staff s on h.staffid=s.staffid where h.temptimesheetid = t.temptimesheetid and h.newstatus = 100 order by whenentered desc),null) as completedat, NetGetVacancySiteDetails(vacancy.vacancyID) as companyaddress, person.payrollnumber, ifnull(nullif(string(t.imageblobid,t.ScanPathFileName),''),0,1) as hasScannedImage, period, dateformat(weekenddate(round(period/100,0),period-(round(period/100,0))*100),'yyyy-mm-dd'), isnull((select list(distinct orderedby) from tempshiftplan pl key join tempshift key join temptimesheet ts where ts.temptimesheetid=t.temptimesheetid),'N/R') as OrderedByList 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 t.temptimesheetid = ptemptimesheetid and nethaspermission(pWebUserID,person.personid,company.companyid)=1 end /* DOC 2017-04-11 PC IW-204 Period added 2017-04-26 PC IW-204 week ending date added 2017-06-22 PC Test and doc 2017-10-23 PC ASA-12 RC2 2017-10-27 PC ASA-11 Person who ordered shift 2017-11-15 PC IW-311 position is drawn from the employment, then the vacancy 2018-04-30 PC modify to over-ride default work pattern where shifts are present 2018-05-29 MHS IW-553 Make it obey tempdesk.ShiftsOnContractTimesheet rather than the presence of shifts. Simplify tests and make pass. 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 */ /* TEST call NetTestSetup(''); insert into temptimesheet (temptimesheetid,placementid,period,periodlength,serialnumber,tempdeskid,personid) on existing update defaults off values ('TEST','TEST',weekcontaining(now(*)),'W',99,'test','TEST'); select serialnumber from NetTimesheet('test.candidate','TEST'); expect serialnumber=99; */ }