====== pears.TSQueryLog ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Description ===== Timesheet Queries - current state of each Query (log is an inaccurate description) ===== Columns ===== ^ Column ^ Type ^ Null ^ Default ^ Comment ^ | **TSQueryLogID** | char(20) | NOT NULL | | | | RefNo | integer | NULL | autoincrement | | | ReasonCode | char(5) | NOT NULL | | | | TempDeskID | char(20) | NULL | | | | PersonID | char(20) | NULL | | | | TempProvTimeSheetID | char(20) | NULL | | | | FileNamePath | char(250) | NULL | | | | Notes | long varchar | NULL | | | | WhenEntered | timestamp | NULL | current timestamp | | | WhoEntered | char(20) | NULL | | | | PersonName | char(100) | NULL | | | | ClientName | char(100) | NULL | | | | Status | char(1) | NULL | | A=archived, F=requires front attention=owner front, B=requires back attention=owner back, T=requires TI attention=owner TI | | Orientation | smallint | NULL | | | | TempTimeSheetID | char(20) | NULL | | | | Source | char(1) | NULL | | | | ImageBlobID | char(20) | NULL | | | | WebOrigin | smallint | NULL | 0 | | | ClientContactName | char(255) | NULL | | | | ClientContactPhone | char(255) | NULL | | | | ClientContactEmail | char(255) | NULL | | | ===== Primary Key ===== * TSQueryLogID ===== Foreign Keys ===== ^ Constraint ^ Columns ^ References ^ Delete/update action ^ | TempDesk | TempDeskID | [[database:tables:pears_tempdesk|pears.tempdesk (tempdeskid)]] | ON DELETE SET NULL | | Person | PersonID | [[database:tables:pears_person|pears.Person (personid)]] | ON DELETE SET NULL | | TempProvTimeSheet | TempProvTimeSheetID | [[database:tables:pears_tempprovtimesheet|pears.TempProvTimeSheet (TempProvTimeSheetID)]] | ON DELETE SET NULL | | TempTimeSheet | TempTimeSheetID | [[database:tables:pears_temptimesheet|pears.TempTimeSheet (TempTimeSheetID)]] | ON DELETE SET NULL | | TSQueryReasons | ReasonCode | [[database:tables:pears_tsqueryreasons|pears.TSQueryReasons (ReasonCode)]] | NOT NULL; | ===== Referenced By ===== ^ Table ^ Constraint ^ Columns ^ Referenced columns ^ | [[database:tables:pears_tsimage|pears.TSImage]] | TSQueryLog | TSQueryLogID | TSQueryLogID | | [[database:tables:pears_tsqueryhistory|pears.TSQueryHistory]] | TSQueryLog | TSQueryLogID | TSQueryLogID | ===== Indexes ===== ^ Name ^ Type ^ Columns ^ Detail ^ | TSQueryLog_WhenEntered | Index | WhenEntered | | ===== Triggers ===== ^ Name ^ Timing ^ Event ^ | TSQueryLoginsert | before | insert order 1 | | TSQueryLogupdate | before | update order 1 | ===== Original SQL ===== -- IQX database structure split by table -- Source: IQXDatabaseStructure - with comments.sql -- Table: "pears"."TSQueryLog" -- Table comment: Timesheet Queries - current state of each Query (log is an inaccurate description) -- Statement count: 13 CREATE TABLE "pears"."TSQueryLog" ( "TSQueryLogID" char(20) NOT NULL ,"RefNo" integer NULL DEFAULT autoincrement ,"ReasonCode" char(5) NOT NULL ,"TempDeskID" char(20) NULL ,"PersonID" char(20) NULL ,"TempProvTimeSheetID" char(20) NULL ,"FileNamePath" char(250) NULL ,"Notes" long varchar NULL ,"WhenEntered" timestamp NULL DEFAULT current timestamp ,"WhoEntered" char(20) NULL ,"PersonName" char(100) NULL ,"ClientName" char(100) NULL ,"Status" char(1) NULL ,"Orientation" smallint NULL ,"TempTimeSheetID" char(20) NULL ,"Source" char(1) NULL ,"ImageBlobID" char(20) NULL ,"WebOrigin" smallint NULL DEFAULT 0 ,"ClientContactName" char(255) NULL ,"ClientContactPhone" char(255) NULL ,"ClientContactEmail" char(255) NULL ,PRIMARY KEY ("TSQueryLogID" ASC) ) go COMMENT ON COLUMN "pears"."TSQueryLog"."Status" IS 'A=archived, F=requires front attention=owner front, B=requires back attention=owner back, T=requires TI attention=owner TI' go COMMENT ON TABLE "pears"."TSQueryLog" IS 'Timesheet Queries - current state of each Query (log is an inaccurate description)' go ALTER TABLE "pears"."TSQueryLog" ADD FOREIGN KEY "TempDesk" ("TempDeskID" ASC) REFERENCES "pears"."tempdesk" ("tempdeskid") ON DELETE SET NULL go ALTER TABLE "pears"."TSQueryLog" ADD FOREIGN KEY "Person" ("PersonID" ASC) REFERENCES "pears"."Person" ("personid") ON DELETE SET NULL go ALTER TABLE "pears"."TSQueryLog" ADD FOREIGN KEY "TempProvTimeSheet" ("TempProvTimeSheetID" ASC) REFERENCES "pears"."TempProvTimeSheet" ("TempProvTimeSheetID") ON DELETE SET NULL go ALTER TABLE "pears"."TSQueryLog" ADD FOREIGN KEY "TempTimeSheet" ("TempTimeSheetID" ASC) REFERENCES "pears"."TempTimeSheet" ("TempTimeSheetID") ON DELETE SET NULL go ALTER TABLE "pears"."TSQueryLog" ADD NOT NULL FOREIGN KEY "TSQueryReasons" ("ReasonCode" ASC) REFERENCES "pears"."TSQueryReasons" ("ReasonCode") go CREATE INDEX "TSQueryLog_WhenEntered" ON "pears"."TSQueryLog" ( "WhenEntered" ) go create trigger "TSQueryLoginsert" before insert order 1 on "pears"."TSQueryLog" referencing new as "new_tsq" for each row begin if("new_tsq"."WhoEntered" is null) and("varexists"("userstaffid") = 1) then set "new_tsq"."WhoEntered" = "userstaffid" end if; if exists(select * from "wpkglobalswitchsetting" where "wpkglobalswitchid" = 'TSQUERYPOPUP' and "value" = 'Y') and("new_tsq"."WhoEntered" is not null) and("new_tsq"."Tempdeskid" is not null) and("new_tsq"."Status" = 'F') then -- have a tempdesk, is for front office and the switch is on for "StaffLoop" as "StaffCursor" no scroll cursor for select "StaffID" as @StaffID from "staff" where "tempdeskid" = "new_tsq"."Tempdeskid" for read only do insert into "diary"( "diaryid","staffid","diaryfrom","diaryto","personid","description","notes","durationtype","duration","PopupMinutes","PopupTime" ) values( "uniquekey"('x'),@StaffID,current timestamp, current timestamp,"new_tsq"."Personid", "string"('A Timesheet Query was created ',"new_tsq"."RefNo"), "string"('Temp - ',(select "name" from "person" where "personid" = "new_tsq"."Personid"),"char"(13),'Desk - ',(select "name" from "tempdesk" where "tempdeskid" = "new_tsq"."TempdeskID"), "char"(13),'Created by - ',(select "name" from "staff" where "staffid" = "new_tsq"."WhoEntered"), "char"(13),'Reason - ',(select "reasonname" from "TSQueryReasons" where "reasoncode" = "new_tsq"."reasoncode"), "char"(13),'Timesheet - ',(select "serialnumber" from "tempprovtimesheet" where "tempprovtimesheetid" = "new_tsq"."tempprovtimesheetid"),"char"(13), 'Notes - ',"new_tsq"."notes"),'R',0,0,"dateadd"("second",1,current timestamp) ) end for end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TSQueryLog"."TSQueryLoginsert" IS {create trigger TSQueryLoginsert before insert order 1 on pears.TSQueryLog referencing new as new_tsq for each row begin if(new_tsq.WhoEntered is null) and(varexists(userstaffid) = 1) then set new_tsq.WhoEntered = userstaffid end if; if exists(select * from wpkglobalswitchsetting where wpkglobalswitchid = 'TSQUERYPOPUP' and value = 'Y') and(new_tsq.WhoEntered is not null) and(new_tsq.Tempdeskid is not null) and(new_tsq.Status = 'F') then -- have a tempdesk, is for front office and the switch is on for StaffLoop as StaffCursor no scroll cursor for select StaffID as @StaffID from staff where tempdeskid = new_tsq.Tempdeskid for read only do insert into diary( diaryid,staffid,diaryfrom,diaryto,personid,description,notes,durationtype,duration,PopupMinutes,PopupTime ) values( uniquekey('x'),@StaffID,current timestamp, current timestamp,new_tsq.Personid, string('A Timesheet Query was created ',new_tsq.RefNo), string('Temp - ',(select name from person where personid = new_tsq.Personid),"char"(13),'Desk - ',(select name from tempdesk where tempdeskid = new_tsq.TempdeskID), "char"(13),'Created by - ',(select name from staff where staffid = new_tsq.WhoEntered), "char"(13),'Reason - ',(select reasonname from TSQueryReasons where reasoncode = new_tsq.reasoncode), "char"(13),'Timesheet - ',(select serialnumber from tempprovtimesheet where tempprovtimesheetid = new_tsq.tempprovtimesheetid),"char"(13), 'Notes - ',new_tsq.notes),'R',0,0,dateadd(second,1,current timestamp) ) end for end if end } go create trigger "TSQueryLogupdate" before update order 1 on "pears"."TSQueryLog" referencing old as "old_tsq" new as "new_tsq" for each row begin if "old_tsq"."status" <> "new_tsq"."status" then if exists(select * from "wpkglobalswitchsetting" where "wpkglobalswitchid" = 'TSQUERYPOPUP' and "value" = 'Y') and("new_tsq"."WhoEntered" is not null) and("new_tsq"."Tempdeskid" is not null) and("new_tsq"."Status" = 'F') then -- have a tempdesk, is for front office and the switch is on for "StaffLoop" as "StaffCursor" no scroll cursor for select "StaffID" as @StaffID from "staff" where "tempdeskid" = "new_tsq"."Tempdeskid" for read only do insert into "diary"( "diaryid","staffid","diaryfrom","diaryto","personid","description","notes","durationtype","duration","PopupMinutes","PopupTime" ) values( "uniquekey"('x'),@StaffID,current timestamp, current timestamp,"new_tsq"."Personid", "string"('A Timesheet Query was transferred ',"new_tsq"."RefNo"), "string"('Temp - ',(select "name" from "person" where "personid" = "new_tsq"."Personid"),"char"(13),'Desk - ',(select "name" from "tempdesk" where "tempdeskid" = "new_tsq"."TempdeskID"), "char"(13),'Created by - ',(select "name" from "staff" where "staffid" = "new_tsq"."WhoEntered"), "char"(13),'Reason - ',(select "reasonname" from "TSQueryReasons" where "reasoncode" = "new_tsq"."reasoncode"), "char"(13),'Timesheet - ',(select "serialnumber" from "tempprovtimesheet" where "tempprovtimesheetid" = "new_tsq"."tempprovtimesheetid"),"char"(13), 'Notes - ',"new_tsq"."notes"),'R',0,0,"dateadd"("second",1,current timestamp) ) end for end if end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TSQueryLog"."TSQueryLogupdate" IS {create trigger TSQueryLogupdate before update order 1 on pears.TSQueryLog referencing old as old_tsq new as new_tsq for each row begin if old_tsq.status<>new_tsq.status then if exists(select * from wpkglobalswitchsetting where wpkglobalswitchid = 'TSQUERYPOPUP' and value = 'Y') and(new_tsq.WhoEntered is not null) and(new_tsq.Tempdeskid is not null) and(new_tsq.Status = 'F') then -- have a tempdesk, is for front office and the switch is on for StaffLoop as StaffCursor no scroll cursor for select StaffID as @StaffID from staff where tempdeskid = new_tsq.Tempdeskid for read only do insert into diary( diaryid,staffid,diaryfrom,diaryto,personid,description,notes,durationtype,duration,PopupMinutes,PopupTime ) values( uniquekey('x'),@StaffID,current timestamp, current timestamp,new_tsq.Personid, string('A Timesheet Query was transferred ',new_tsq.RefNo), string('Temp - ',(select name from person where personid = new_tsq.Personid),"char"(13),'Desk - ',(select name from tempdesk where tempdeskid = new_tsq.TempdeskID), "char"(13),'Created by - ',(select name from staff where staffid = new_tsq.WhoEntered), "char"(13),'Reason - ',(select reasonname from TSQueryReasons where reasoncode = new_tsq.reasoncode), "char"(13),'Timesheet - ',(select serialnumber from tempprovtimesheet where tempprovtimesheetid = new_tsq.tempprovtimesheetid),"char"(13), 'Notes - ',new_tsq.notes),'R',0,0,dateadd(second,1,current timestamp) ) end for end if end if end } go