Show pageOld revisionsBacklinksExport to PDFFold/unfold allBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== pears.TempShiftPlan ====== <WRAP center round info> Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. </WRAP> ===== Description ===== Shift requirements. Linked to TempShift when booked / worked / billed / paid etc. ===== Columns ===== ^ Column ^ Type ^ Null ^ Default ^ Comment ^ | **TempShiftPlanID** | char(20) | NOT NULL | | | | VacancyID | char(20) | NOT NULL | | | | EssentialSkill | char(15) | NULL | | P|A;TagID;TagChoiceID;GradeTagID | | EssentialSkillGradeID | char(4) | NULL | | | | Description | char(50) | NOT NULL | | | | TimeFrom | time | NULL | | | | TimeTo | time | NULL | | | | Moveable | smallint | NULL | 0 | | | Minutes | smallint | NULL | | Fill if shorter spell within the timespan | | BreakMinutes | smallint | NULL | | | | ShiftDate | date | NULL | | | | ReferenceRequired | char(1) | NULL | | on <E>ntry, <C>onfirmation, <T>imesheet entry. Blank for not required | | ClientMustConfirm | smallint | NULL | 0 | | | WhenEntered | timestamp | NULL | current timestamp | | | ReferenceCode | char(20) | NULL | | | | EssentialSkillChoiceList | char(100) | NULL | | | | TempMustConfirm | smallint | NULL | 0 | | | StaffID | char(20) | NULL | | | | OrderedBy | char(50) | NULL | | | | TempShiftTypeID | char(2) | NULL | | | | AnalysisCode | char(20) | NULL | | | | ShiftSerialNumber | bigint | NULL | autoincrement | | | TemporaryID | char(20) | NULL | | Internal use only | | CascadeDateTime | timestamp | NULL | | When next cascade will take place | | CascadeLevel | smallint | NULL | 0 | 0 if has not yet been cascaded | | RecoveryHours | smallint | NULL | 0 | | | TempShiftOrderReasonID | char(20) | NULL | | | | ClientNote | char(50) | NULL | | | | TemporaryPersonID | char(20) | NULL | | Internal use only | | ColourOverride | smallint | NULL | 0 | | | TempShiftTemplateID | char(20) | NULL | | | | MasterRosterShiftID | char(20) | NULL | | | ===== Primary Key ===== * TempShiftPlanID ===== Foreign Keys ===== ^ Constraint ^ Columns ^ References ^ Delete/update action ^ | Vacancy | VacancyID | [[database:tables:pears_vacancy|pears.vacancy (vacancyid)]] | NOT NULL; ON DELETE CASCADE | | Staff | StaffID | [[database:tables:pears_staff|pears.staff (staffid)]] | ON DELETE SET NULL | | TempShiftType | TempShiftTypeID | [[database:tables:pears_tempshifttype|pears.TempShiftType (TempShiftTypeID)]] | | | TempShiftOrderReason | TempShiftOrderReasonID | [[database:tables:pears_tempshiftorderreason|pears.TempShiftOrderReason (TempShiftOrderReasonID)]] | | | TempShiftTemplate | TempShiftTemplateID | [[database:tables:pears_tempshifttemplate|pears.TempShiftTemplate (TempShiftTemplateID)]] | | | MasterRosterShift | MasterRosterShiftID | [[database:tables:pears_masterrostershift|pears.MasterRosterShift (MasterRosterShiftID)]] | ON DELETE SET NULL | ===== Referenced By ===== ^ Table ^ Constraint ^ Columns ^ Referenced columns ^ | [[database:tables:pears_automatchnotificationqueue|pears.AutoMatchNotificationQueue]] | tempshiftplan | TempShiftPlanID | TempShiftPlanID | | [[database:tables:pears_automatchshiftqueue|pears.AutoMatchShiftQueue]] | tempshiftplan | TempShiftPlanID | TempShiftPlanID | | [[database:tables:pears_cascadedshift|pears.CascadedShift]] | TempShiftPlan | TempshiftPlanID | TempShiftPlanID | | [[database:tables:pears_iqxnetcandidateshifts|pears.IQXNetCandidateShifts]] | TempShiftPlan | TempShiftPlanID | TempShiftPlanID | | [[database:tables:pears_tempshift|pears.TempShift]] | TempShiftPlan | TempShiftPlanID | TempShiftPlanID | | [[database:tables:pears_tempshiftplanauthorise|pears.TempShiftPlanAuthorise]] | TempShiftPlan | TempShiftPlanID | TempShiftPlanID | | [[database:tables:pears_tempshiftprogress|pears.TempShiftProgress]] | TempShiftPlan | TempShiftPlanID | TempShiftPlanID | ===== Indexes ===== ^ Name ^ Type ^ Columns ^ Detail ^ | ShiftPlan_TempID | Index | TemporaryID | | | ShiftPlan_SerialNo | Index | ShiftSerialNumber | | | ShiftPlan_Cascade | Index | CascadeDateTime | | | ShiftPlan_WhenEntered | Index | WhenEntered | | | ShiftPlan_AnalysisCode | Index | AnalysisCode | | ===== Triggers ===== ^ Name ^ Timing ^ Event ^ | ShiftPlan_Insert | before | insert order 1 | | TempShiftPlanAudit | after | update of "VacancyID", "TimeFrom","TimeTo","Minutes", "BreakMinutes","RecoveryHours","TempShiftOrderReasonID" order 2 | | psHealthTempShiftPlanInsert | after | insert order 900 | | psHealthTempShiftPlanUpdate | after | update of "shiftdate", "timefrom","timeto" order 900 | | ShiftPlan_InsertTrim | before | insert order 2 | | ShiftPlan_UpdateTrim | before | update order 1 | | AutoMatchShiftPlanInsertUpdate | after | insert,update order 3 | ===== Original SQL ===== <code sql> -- IQX database structure split by table -- Source: IQXDatabaseStructure - with comments.sql -- Table: "pears"."TempShiftPlan" -- Table comment: Shift requirements. Linked to TempShift when booked / worked / billed / paid etc. -- Statement count: 32 CREATE TABLE "pears"."TempShiftPlan" ( "TempShiftPlanID" char(20) NOT NULL ,"VacancyID" char(20) NOT NULL ,"EssentialSkill" char(15) NULL ,"EssentialSkillGradeID" char(4) NULL ,"Description" char(50) NOT NULL ,"TimeFrom" time NULL ,"TimeTo" time NULL ,"Moveable" smallint NULL DEFAULT 0 ,"Minutes" smallint NULL ,"BreakMinutes" smallint NULL ,"ShiftDate" date NULL ,"ReferenceRequired" char(1) NULL ,"ClientMustConfirm" smallint NULL DEFAULT 0 ,"WhenEntered" timestamp NULL DEFAULT current timestamp ,"ReferenceCode" char(20) NULL ,"EssentialSkillChoiceList" char(100) NULL ,"TempMustConfirm" smallint NULL DEFAULT 0 ,"StaffID" char(20) NULL ,"OrderedBy" char(50) NULL ,"TempShiftTypeID" char(2) NULL ,"AnalysisCode" char(20) NULL ,"ShiftSerialNumber" bigint NULL DEFAULT autoincrement ,"TemporaryID" char(20) NULL ,"CascadeDateTime" timestamp NULL ,"CascadeLevel" smallint NULL DEFAULT 0 ,"RecoveryHours" smallint NULL DEFAULT 0 ,"TempShiftOrderReasonID" char(20) NULL ,"ClientNote" char(50) NULL ,"TemporaryPersonID" char(20) NULL ,"ColourOverride" smallint NULL DEFAULT 0 ,"TempShiftTemplateID" char(20) NULL ,"MasterRosterShiftID" char(20) NULL ,PRIMARY KEY ("TempShiftPlanID" ASC) ) go COMMENT ON COLUMN "pears"."TempShiftPlan"."EssentialSkill" IS 'P|A;TagID;TagChoiceID;GradeTagID' go COMMENT ON COLUMN "pears"."TempShiftPlan"."Minutes" IS 'Fill if shorter spell within the timespan' go COMMENT ON COLUMN "pears"."TempShiftPlan"."ReferenceRequired" IS 'on <E>ntry, <C>onfirmation, <T>imesheet entry. Blank for not required' go COMMENT ON COLUMN "pears"."TempShiftPlan"."TemporaryID" IS 'Internal use only' go COMMENT ON COLUMN "pears"."TempShiftPlan"."CascadeDateTime" IS 'When next cascade will take place' go COMMENT ON COLUMN "pears"."TempShiftPlan"."CascadeLevel" IS '0 if has not yet been cascaded' go COMMENT ON COLUMN "pears"."TempShiftPlan"."TemporaryPersonID" IS 'Internal use only' go COMMENT ON TABLE "pears"."TempShiftPlan" IS 'Shift requirements. Linked to TempShift when booked / worked / billed / paid etc.' go ALTER TABLE "pears"."TempShiftPlan" ADD NOT NULL FOREIGN KEY "Vacancy" ("VacancyID" ASC) REFERENCES "pears"."vacancy" ("vacancyid") ON DELETE CASCADE go ALTER TABLE "pears"."TempShiftPlan" ADD FOREIGN KEY "Staff" ("StaffID" ASC) REFERENCES "pears"."staff" ("staffid") ON DELETE SET NULL go ALTER TABLE "pears"."TempShiftPlan" ADD FOREIGN KEY "TempShiftType" ("TempShiftTypeID" ASC) REFERENCES "pears"."TempShiftType" ("TempShiftTypeID") go ALTER TABLE "pears"."TempShiftPlan" ADD FOREIGN KEY "TempShiftOrderReason" ("TempShiftOrderReasonID" ASC) REFERENCES "pears"."TempShiftOrderReason" ("TempShiftOrderReasonID") go ALTER TABLE "pears"."TempShiftPlan" ADD FOREIGN KEY "TempShiftTemplate" ("TempShiftTemplateID" ASC) REFERENCES "pears"."TempShiftTemplate" ("TempShiftTemplateID") go ALTER TABLE "pears"."TempShiftPlan" ADD FOREIGN KEY "MasterRosterShift" ("MasterRosterShiftID" ASC) REFERENCES "pears"."MasterRosterShift" ("MasterRosterShiftID") ON DELETE SET NULL go CREATE INDEX "ShiftPlan_TempID" ON "pears"."TempShiftPlan" ( "TemporaryID" ) go CREATE INDEX "ShiftPlan_SerialNo" ON "pears"."TempShiftPlan" ( "ShiftSerialNumber" ) go CREATE INDEX "ShiftPlan_Cascade" ON "pears"."TempShiftPlan" ( "CascadeDateTime" ) go CREATE INDEX "ShiftPlan_WhenEntered" ON "pears"."TempShiftPlan" ( "WhenEntered" ) go CREATE INDEX "ShiftPlan_AnalysisCode" ON "pears"."TempShiftPlan" ( "AnalysisCode" ) go create trigger "ShiftPlan_Insert" before insert order 1 on "pears"."TempShiftPlan" referencing new as "new_shift" for each row when("new_shift"."staffid" is null) begin set "new_shift"."staffid" = "userstaffid" exception when others then set "new_shift"."staffid" = null end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TempShiftPlan"."ShiftPlan_Insert" IS {create trigger ShiftPlan_Insert before insert order 1 on pears.TempShiftPlan referencing new as new_shift for each row when(new_shift.staffid is null) begin set new_shift.staffid=userstaffid exception when others then set new_shift.staffid=null end } go create trigger "TempShiftPlanAudit" after update of "VacancyID", "TimeFrom","TimeTo","Minutes", "BreakMinutes","RecoveryHours","TempShiftOrderReasonID" order 2 on "pears"."TempShiftPlan" referencing old as "OldShift" new as "NewShift" for each row when(exists(select * from "AuditItems" where "AreaName" = 'ShiftPlan' and "AuditFlag" = 1)) begin declare "AuditList" long varchar; declare "NewRefCode" char(20); select "string"(',',"list"("ItemName"),',') into "AuditList" from "AuditItems" where "AreaName" = 'ShiftPlan' and "AuditFlag" = 1; select "RefCode" into "NewRefCode" from "Vacancy" where "Vacancy"."VacancyID" = "NewShift"."VacancyID"; if "locate"("AuditList",',Moving,') > 0 and update("VacancyID") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID",'Shift Plan ' || "NewShift"."ShiftSerialNumber" || ' moved between vacancies', "string"('Original OurRef: ',"NewRefCode",', Original VacancyID: ',"OldShift"."VacancyID"), "string"('New OurRef: ',"NewRefCode",', New VacancyID: ',"NewShift"."VacancyID")) end if; if "locate"("AuditList",',Times,') > 0 then if update("RecoveryHours") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID",'Shift Plan ' || "NewShift"."ShiftSerialNumber" || ' Recovery Hours edited OurRef: ' || "NewRefCode", "OldShift"."RecoveryHours", "NewShift"."RecoveryHours") end if; if update("Minutes") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID",'Shift Plan ' || "NewShift"."ShiftSerialNumber" || ' Minutes edited OurRef: ' || "NewRefCode", "OldShift"."Minutes", "NewShift"."Minutes") end if; if update("BreakMinutes") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID",'Shift Plan ' || "NewShift"."ShiftSerialNumber" || ' Break Minutes edited OurRef: ' || "NewRefCode", "OldShift"."BreakMinutes", "NewShift"."BreakMinutes") end if; if update("TimeFrom") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID",'Shift Plan ' || "NewShift"."ShiftSerialNumber" || ' From edited OurRef: ' || "NewRefCode", "OldShift"."TimeFrom", "NewShift"."TimeFrom") end if; if update("TimeTo") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID",'Shift Plan ' || "NewShift"."ShiftSerialNumber" || ' To edited OurRef: ' || "NewRefCode", "OldShift"."TimeTo", "NewShift"."TimeTo") end if end if; if "locate"("AuditList",',Order Reason,') > 0 then if update("TempShiftOrderReasonID") then call "AuditLog"('SHIFTPLAN',"NewShift"."TempShiftPlanID","string"('Shift Plan ',"NewShift"."ShiftSerialNumber",' Our Ref: ',"NewRefCode",' Order Reason Changed - ', (select "description" from "tempshiftorderreason" as "r" where "r"."tempshiftorderreasonid" = "OldShift"."TempshiftorderreasonID"),' to ', (select "description" from "tempshiftorderreason" as "r" where "r"."tempshiftorderreasonid" = "newShift"."TempshiftorderreasonID")), "OldShift"."TempshiftorderreasonID","NewShift"."TempshiftorderreasonID") end if end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TempShiftPlan"."TempShiftPlanAudit" IS {create trigger TempShiftPlanAudit after update of VacancyID, TimeFrom,TimeTo,Minutes, BreakMinutes,RecoveryHours,TempShiftOrderReasonID order 2 on pears.TempShiftPlan referencing old as OldShift new as NewShift for each row when(exists(select * from AuditItems where AreaName = 'ShiftPlan' and AuditFlag = 1)) begin declare AuditList long varchar; declare NewRefCode char(20); select string(',',list(ItemName),',') into AuditList from AuditItems where AreaName = 'ShiftPlan' and AuditFlag = 1; select RefCode into NewRefCode from Vacancy where Vacancy.VacancyID = NewShift.VacancyID; if locate(AuditList,',Moving,') > 0 and update(VacancyID) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID,'Shift Plan '||NewShift.ShiftSerialNumber||' moved between vacancies', string('Original OurRef: ',NewRefCode,', Original VacancyID: ',OldShift.VacancyID), string('New OurRef: ',NewRefCode,', New VacancyID: ',NewShift.VacancyID)) end if; if locate(AuditList,',Times,') > 0 then if update(RecoveryHours) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID,'Shift Plan '||NewShift.ShiftSerialNumber||' Recovery Hours edited OurRef: ' || NewRefCode, OldShift.RecoveryHours, NewShift.RecoveryHours) end if; if update(Minutes) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID,'Shift Plan '||NewShift.ShiftSerialNumber||' Minutes edited OurRef: ' || NewRefCode, OldShift.Minutes, NewShift.Minutes) end if; if update(BreakMinutes) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID,'Shift Plan '||NewShift.ShiftSerialNumber||' Break Minutes edited OurRef: ' || NewRefCode, OldShift.BreakMinutes, NewShift.BreakMinutes) end if; if update(TimeFrom) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID,'Shift Plan '||NewShift.ShiftSerialNumber||' From edited OurRef: ' || NewRefCode, OldShift.TimeFrom, NewShift.TimeFrom) end if; if update(TimeTo) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID,'Shift Plan '||NewShift.ShiftSerialNumber||' To edited OurRef: ' || NewRefCode, OldShift.TimeTo, NewShift.TimeTo) end if; end if; if locate(AuditList,',Order Reason,') > 0 then if update(TempShiftOrderReasonID) then call AuditLog('SHIFTPLAN',NewShift.TempShiftPlanID, string('Shift Plan ',NewShift.ShiftSerialNumber,' Our Ref: ' ,NewRefCode, ' Order Reason Changed - ' , (select description from tempshiftorderreason r where r.tempshiftorderreasonid = OldShift.TempshiftorderreasonID), ' to ', (select description from tempshiftorderreason r where r.tempshiftorderreasonid = newShift.TempshiftorderreasonID)) , OldShift.TempshiftorderreasonID, NewShift. TempshiftorderreasonID) end if end if end } go create trigger "psHealthTempShiftPlanInsert" after insert order 900 on "pears"."tempshiftplan" referencing new as "new_rec" for each row begin if "psHealthCanSendShift"(null,"new_rec"."tempshiftplanid") = 1 then call "psHealthInsertUpdateShift"(null,"new_rec"."tempshiftplanid") end if end go create trigger "psHealthTempShiftPlanUpdate" after update of "shiftdate", "timefrom","timeto" order 900 on "pears"."tempshiftplan" referencing new as "new_rec" for each row begin if "psHealthCanSendShift"(null,"new_rec"."tempshiftplanid") = 1 then call "psHealthInsertUpdateShift"(null,"new_rec"."tempshiftplanid") end if end go create trigger "ShiftPlan_InsertTrim" before insert order 2 on "pears"."TempShiftPlan" referencing new as "new_shift" for each row begin set "new_shift"."referencecode" = "trim"("new_shift"."referencecode") end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TempShiftPlan"."ShiftPlan_InsertTrim" IS {create trigger ShiftPlan_InsertTrim before insert order 2 on pears.TempShiftPlan referencing new as new_shift for each row begin set new_shift.referencecode = trim(new_shift.referencecode) end } go create trigger "ShiftPlan_UpdateTrim" before update order 1 on "pears"."TempShiftPlan" referencing new as "new_shift" for each row begin set "new_shift"."referencecode" = "trim"("new_shift"."referencecode") end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TempShiftPlan"."ShiftPlan_UpdateTrim" IS {create trigger ShiftPlan_UpdateTrim before update order 1 on pears.TempShiftPlan referencing new as new_shift for each row begin set new_shift.referencecode = trim(new_shift.referencecode) end } go create trigger "AutoMatchShiftPlanInsertUpdate" after insert,update order 3 on "pears"."TempShiftPlan" referencing new as "New_Shift" for each row when("AutoMatchingEnabled" = 'Y') begin -- This trigger maintains the list of shifts to be checked for needing to be (re-)matched -- DELETE is ignored as referential integrity will deal with that if(select "TempDesk"."AutoMatchOn" from "TempDesk" key join "Vacancy" as "v" where "v"."VacancyID" = "New_Shift"."VacancyID") = 1 then if inserting then call "AutoMatchAddShiftToQueue"("New_Shift"."TempShiftPlanID",'INSERT') elseif updating then call "AutoMatchAddShiftToQueue"("New_Shift"."TempShiftPlanID",'UPDATING') end if end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."TempShiftPlan"."AutoMatchShiftPlanInsertUpdate" IS {create trigger AutoMatchShiftPlanInsertUpdate AFTER INSERT, UPDATE ORDER 3 ON pears.TempShiftPlan REFERENCING NEW as New_Shift FOR EACH ROW WHEN (AutoMatchingEnabled = 'Y') BEGIN -- This trigger maintains the list of shifts to be checked for needing to be (re-)matched -- DELETE is ignored as referential integrity will deal with that if (select TempDesk.AutoMatchOn from TempDesk key join Vacancy v where v.VacancyID = New_Shift.VacancyID) = 1 then if INSERTING then call AutoMatchAddShiftToQueue(New_Shift.TempShiftPlanID,'INSERT'); elseif UPDATING then call AutoMatchAddShiftToQueue(New_Shift.TempShiftPlanID,'UPDATING') end if; end if; END } go </code> database/tables/pears_tempshiftplan.txt Last modified: 2026/08/07 19:24by 127.0.0.1