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.vacancy ====== <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 ===== Header record for Vacancies. ===== Columns ===== ^ Column ^ Type ^ Null ^ Default ^ Comment ^ | **vacancyid** | char(20) | NOT NULL | | | | departmentid | char(2) | NOT NULL | | | | employmentid | char(20) | NOT NULL | | | | staffid | char(20) | NULL | | | | expiry | date | NULL | | | | entrydate | date | NULL | | | | status | char(1) | NULL | | | | startdate | date | NULL | | | | ontargetearn | numeric(12,2) | NULL | | | | salary | numeric(12,2) | NULL | | | | clientrate | numeric(12,2) | NULL | | | | temprate | numeric(12,2) | NULL | | | | temp | smallint | NOT NULL | 0 | | | position | char(50) | NULL | | | | notes | long varchar | NULL | | | | othernotes | long varchar | NULL | | | | whynotfilled | char(50) | NULL | | | | classcode | char(1) | NULL | | | | refcode | char(20) | NULL | | | | noofposts | integer | NULL | 0 | | | ErNI | double | NULL | | | | HolidayAllowance | double | NULL | | | | Discount | double | NULL | | | | FinishDate | date | NULL | | | | TempDeskID | char(20) | NULL | | | | TheirRef | char(50) | NULL | | | | ContractRef | char(20) | NULL | | | | PayrollIdentifier | char(1) | NULL | | For external payroll link | | AnalysisCode | char(20) | NULL | | | | clientdepartment | char(30) | NULL | | | | TransferBatch | integer | NULL | | | | ExtNumber | integer | NULL | | | | Currency | char(3) | NULL | | | | RecipientID | char(20) | NULL | | | | PriceListID | char(20) | NULL | | | | Funder1 | char(12) | NULL | | | | Funder2 | char(12) | NULL | | | | Funder3 | char(12) | NULL | | | | Role | char(35) | NULL | | Allows autogeneration of position for recipient based vacancies | | Funder1Limit | double | NULL | | | | Funder2Limit | double | NULL | | | | Funder3Limit | double | NULL | | | | SiteName | char(50) | NULL | | | | SiteContact | char(100) | NULL | | | | addr1 | char(40) | NULL | | | | addr2 | char(40) | NULL | | | | addr3 | char(40) | NULL | | | | town | char(30) | NULL | | | | county | char(30) | NULL | | | | country | char(30) | NULL | | | | postcode | char(20) | NULL | | | | SitePhoneNumbers | char(100) | NULL | | | | TempJobTypeID | char(20) | NULL | | | | Invaddr1 | char(40) | NULL | | | | Invaddr2 | char(40) | NULL | | | | Invaddr3 | char(40) | NULL | | | | Invtown | char(30) | NULL | | | | Invcounty | char(30) | NULL | | | | Invcountry | char(30) | NULL | | | | Invpostcode | char(20) | NULL | | | | DateBecameFinal | date | NULL | | | | SiteFax | char(50) | NULL | | | | SiteEmail | char(250) | NULL | | | | CascadeDateTime | timestamp | NULL | | When next cascade will take place | | Cascaded | smallint | NULL | 0 | | | CascadeLevel | smallint | NULL | 0 | 0 if has not yet been cascaded | | WhenEntered | timestamp | NULL | current timestamp | | | SendShiftsToPayroll | smallint | NULL | 0 | | | WorkMonday | tinyint | NULL | | | | WorkTuesday | tinyint | NULL | | | | WorkWednesday | tinyint | NULL | | | | WorkThursday | tinyint | NULL | | | | WorkFriday | tinyint | NULL | | | | WorkSaturday | tinyint | NULL | | | | WorkSunday | tinyint | NULL | | | | WorkNormalHours | double | NULL | | | | WorkStartTime | time | NULL | | | | documenttemplateid | char(12) | NULL | | | | PDFInvIncTS | tinyint | NULL | 0 | | | lastcontactevent | timestamp | NULL | | Added V2.2.2.13 Will be null for existing vacancies | | InvoiceEmail | char(250) | NULL | | | | Funder1Ref | char(20) | NULL | | | | Funder2Ref | char(20) | NULL | | | | Funder3Ref | char(20) | NULL | | | | AWRTempJobTypeID | char(20) | NULL | | No ref. integ. to avoid breaking existing key join code | | AWRFixedNI | double | NULL | | % | | AWRFixedWTR | double | NULL | | % | | ExtraHols | double | NULL | | Needs Calc version > 3.0 | | QuestionnaireUpdated | timestamp | NULL | | Used to update requirements | | BlockETimesheets | tinyint | NULL | 0 | | | extranotes | long varchar | NULL | | | | OriginID | char(20) | NULL | | This is the new Source | | NotTaxable | smallint | NULL | 0 | Flag to override client public sector | | salaryto | numeric(12,2) | NULL | | | | InvAttnOf | char(100) | NULL | | | | ComplianceDomainID | char(20) | NULL | | | | WarningMessage | long varchar | NULL | | | ===== Primary Key ===== * vacancyid ===== Foreign Keys ===== ^ Constraint ^ Columns ^ References ^ Delete/update action ^ | department | departmentid | [[database:tables:pears_department|pears.Department (departmentid)]] | NOT NULL; | | employment | employmentid | [[database:tables:pears_employment|pears.employment (employmentid)]] | NOT NULL; | | staff | staffid | [[database:tables:pears_staff|pears.staff (staffid)]] | | | vacancyclass | classcode | [[database:tables:pears_vacancyclass|pears.vacancyclass (classcode)]] | | | TempDesk | TempDeskID | [[database:tables:pears_tempdesk|pears.tempdesk (tempdeskid)]] | | | person | RecipientID | [[database:tables:pears_person|pears.Person (personid)]] | ON DELETE SET NULL | | TempPriceList | PriceListID | [[database:tables:pears_temppricelist|pears.TempPriceList (TempPriceListID)]] | ON DELETE SET NULL | | TempJobType | TempJobTypeID | [[database:tables:pears_tempjobtype|pears.TempJobType (TempJobTypeID)]] | ON DELETE SET NULL | | origin | OriginID | [[database:tables:pears_origin|pears.Origin (OriginID)]] | | | ComplianceDomain | ComplianceDomainID | [[database:tables:pears_compliancedomain|pears.ComplianceDomain (ComplianceDomainID)]] | ON DELETE SET NULL | | iqacdocumenttemplate | documenttemplateid | [[database:tables:pears_iqacdocumenttemplate|pears.IQacDocumentTemplate (DocumentTemplateID)]] | ON DELETE SET NULL | ===== Referenced By ===== ^ Table ^ Constraint ^ Columns ^ Referenced columns ^ | [[database:tables:pears_awrjobmaster|pears.AWRJobMaster]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_awrvacancy|pears.AWRvacancy]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_broadbeancandidate|pears.BroadbeanCandidate]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_broadbeanchannels|pears.BroadbeanChannels]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_broadbeanvacancy|pears.BroadbeanVacancy]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_cardreaderoverridesettings|pears.CardReaderOverrideSettings]] | vacancy | VacancyID | vacancyid | | [[database:tables:pears_cascadedvacancy|pears.CascadedVacancy]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_cascaderule|pears.CascadeRule]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_contactevent|pears.contactevent]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_diary|pears.diary]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_docpackvalidation|pears.DocPackValidation]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_masterroster|pears.MasterRoster]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_placement|pears.Placement]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_progress|pears.progress]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_staffhistory|pears.StaffHistory]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_statushistory|pears.StatusHistory]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_tempjobrate|pears.TempJobRate]] | vacancy | VacancyID | vacancyid | | [[database:tables:pears_tempprovtimesheet|pears.TempProvTimeSheet]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_tempsecagencyvacratescheme|pears.TempSecAgencyVacRateScheme]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_tempshift|pears.TempShift]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_tempshiftplan|pears.TempShiftPlan]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_tempshifttemplateallowed|pears.TempShiftTemplateAllowed]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_vacancy_team|pears.vacancy_team]] | vacancy | vacancyid | vacancyid | | [[database:tables:pears_vacancyetip|pears.VacancyEtip]] | vacancy | vacancyID | vacancyid | | [[database:tables:pears_vacancylimit|pears.VacancyLimit]] | vacancy | VacancyID | vacancyid | | [[database:tables:pears_vacancyoverrideratescheme|pears.VacancyOverrideRateScheme]] | Vacancy | VacancyID | vacancyid | | [[database:tables:pears_vacancyroleallocation|pears.VacancyRoleAllocation]] | vacancy | VacancyID | vacancyid | | [[database:tables:pears_withholds|pears.WithHolds]] | vacancy | VacancyID | vacancyid | ===== Indexes ===== ^ Name ^ Type ^ Columns ^ Detail ^ | vacancy_entrydate | Index | entrydate | | | vacancy_refcode | Index | refcode | | | vacancy_extnumber | Index | ExtNumber | | | vacancy_transferbatch | Index | TransferBatch | | | vacancy_status | Index | status | | | person_lastcontactevent | Index | lastcontactevent | | | vacancy_desk_status | Index | TempDeskID, status | | | VacancyWhenEntered | Index | WhenEntered | | | vacancy_notestext | Text index | notes, othernotes | CONFIGURATION "SYS"."default_char" IMMEDIATE REFRESH | ===== Triggers ===== ^ Name ^ Timing ^ Event ^ | VacancyFinal | after | update of "Status" order 1 | | VacancyNoLongerFinal | after | update of "Status" order 2 | | vacancy_lsmupd | before | update of "TheirRef" order 2 | | vacancy_insert | before | insert order 1 | | VacancyAudit | before | update of "employmentid", "departmentid","staffid","expiry","entrydate","status","startdate","salary","position","noofposts","FinishDate", "TempDeskID","RefCode","TheirRef","Payrollidentifier","othernotes","nottaxable","extranotes","sitename","siteemail","addr1","addr2","addr3","postcode","sitecontact","town","county","country","documenttemplateid" order 6 | | vacancy_insert2 | after | insert order 1 | | vacancy_delete | before | delete order 1 | | psHealthVacancyUpdate | after | update of "recipientid" order 900 | | vacancy_UpdateTrim | before | update order 7 | | InsertStatusVacancy | after | insert order 2 | | UpdateStatusVacancy | after | update of "status" order 3 | | VacancyKeyWordsInsert | after | insert order 20 | | VacancyKeyWordsUpdate | after | update of "refcode", "position","siteemail","sitename","sitecontact","employmentid" order 21 | ===== Original SQL ===== <code sql> -- IQX database structure split by table -- Source: IQXDatabaseStructure - with comments.sql -- Table: "pears"."vacancy" -- Table comment: Header record for Vacancies. -- Statement count: 59 CREATE TABLE "pears"."vacancy" ( "vacancyid" char(20) NOT NULL ,"departmentid" char(2) NOT NULL ,"employmentid" char(20) NOT NULL ,"staffid" char(20) NULL ,"expiry" date NULL ,"entrydate" date NULL ,"status" char(1) NULL ,"startdate" date NULL ,"ontargetearn" numeric(12,2) NULL ,"salary" numeric(12,2) NULL ,"clientrate" numeric(12,2) NULL ,"temprate" numeric(12,2) NULL ,"temp" smallint NOT NULL DEFAULT 0 ,"position" char(50) NULL ,"notes" long varchar NULL ,"othernotes" long varchar NULL ,"whynotfilled" char(50) NULL ,"classcode" char(1) NULL ,"refcode" char(20) NULL ,"noofposts" integer NULL DEFAULT 0 ,"ErNI" double NULL ,"HolidayAllowance" double NULL ,"Discount" double NULL ,"FinishDate" date NULL ,"TempDeskID" char(20) NULL ,"TheirRef" char(50) NULL ,"ContractRef" char(20) NULL ,"PayrollIdentifier" char(1) NULL ,"AnalysisCode" char(20) NULL ,"clientdepartment" char(30) NULL ,"TransferBatch" integer NULL ,"ExtNumber" integer NULL ,"Currency" char(3) NULL ,"RecipientID" char(20) NULL ,"PriceListID" char(20) NULL ,"Funder1" char(12) NULL ,"Funder2" char(12) NULL ,"Funder3" char(12) NULL ,"Role" char(35) NULL ,"Funder1Limit" double NULL ,"Funder2Limit" double NULL ,"Funder3Limit" double NULL ,"SiteName" char(50) NULL ,"SiteContact" char(100) NULL ,"addr1" char(40) NULL ,"addr2" char(40) NULL ,"addr3" char(40) NULL ,"town" char(30) NULL ,"county" char(30) NULL ,"country" char(30) NULL ,"postcode" char(20) NULL ,"SitePhoneNumbers" char(100) NULL ,"TempJobTypeID" char(20) NULL ,"Invaddr1" char(40) NULL ,"Invaddr2" char(40) NULL ,"Invaddr3" char(40) NULL ,"Invtown" char(30) NULL ,"Invcounty" char(30) NULL ,"Invcountry" char(30) NULL ,"Invpostcode" char(20) NULL ,"DateBecameFinal" date NULL ,"SiteFax" char(50) NULL ,"SiteEmail" char(250) NULL ,"CascadeDateTime" timestamp NULL ,"Cascaded" smallint NULL DEFAULT 0 ,"CascadeLevel" smallint NULL DEFAULT 0 ,"WhenEntered" timestamp NULL DEFAULT current timestamp ,"SendShiftsToPayroll" smallint NULL DEFAULT 0 ,"WorkMonday" tinyint NULL ,"WorkTuesday" tinyint NULL ,"WorkWednesday" tinyint NULL ,"WorkThursday" tinyint NULL ,"WorkFriday" tinyint NULL ,"WorkSaturday" tinyint NULL ,"WorkSunday" tinyint NULL ,"WorkNormalHours" double NULL ,"WorkStartTime" time NULL ,"documenttemplateid" char(12) NULL ,"PDFInvIncTS" tinyint NULL DEFAULT 0 ,"lastcontactevent" timestamp NULL ,"InvoiceEmail" char(250) NULL ,"Funder1Ref" char(20) NULL ,"Funder2Ref" char(20) NULL ,"Funder3Ref" char(20) NULL ,"AWRTempJobTypeID" char(20) NULL ,"AWRFixedNI" double NULL ,"AWRFixedWTR" double NULL ,"ExtraHols" double NULL ,"QuestionnaireUpdated" timestamp NULL ,"BlockETimesheets" tinyint NULL DEFAULT 0 ,"extranotes" long varchar NULL ,"OriginID" char(20) NULL ,"NotTaxable" smallint NULL DEFAULT 0 ,"salaryto" numeric(12,2) NULL ,"InvAttnOf" char(100) NULL ,"ComplianceDomainID" char(20) NULL ,"WarningMessage" long varchar NULL ,PRIMARY KEY ("vacancyid" ASC) ,CONSTRAINT "TempVacancyMustHaveTempDesk" check("Temp" = 0 or "TempDeskID" is not null) ) go COMMENT ON COLUMN "pears"."vacancy"."PayrollIdentifier" IS 'For external payroll link' go COMMENT ON COLUMN "pears"."vacancy"."Role" IS 'Allows autogeneration of position for recipient based vacancies' go COMMENT ON COLUMN "pears"."vacancy"."CascadeDateTime" IS 'When next cascade will take place' go COMMENT ON COLUMN "pears"."vacancy"."CascadeLevel" IS '0 if has not yet been cascaded' go COMMENT ON COLUMN "pears"."vacancy"."lastcontactevent" IS 'Added V2.2.2.13 Will be null for existing vacancies' go COMMENT ON COLUMN "pears"."vacancy"."AWRTempJobTypeID" IS 'No ref. integ. to avoid breaking existing key join code' go COMMENT ON COLUMN "pears"."vacancy"."AWRFixedNI" IS '%' go COMMENT ON COLUMN "pears"."vacancy"."AWRFixedWTR" IS '%' go COMMENT ON COLUMN "pears"."vacancy"."ExtraHols" IS 'Needs Calc version > 3.0' go COMMENT ON COLUMN "pears"."vacancy"."QuestionnaireUpdated" IS 'Used to update requirements' go COMMENT ON COLUMN "pears"."vacancy"."OriginID" IS 'This is the new Source' go COMMENT ON COLUMN "pears"."vacancy"."NotTaxable" IS 'Flag to override client public sector' go COMMENT ON TABLE "pears"."vacancy" IS 'Header record for Vacancies.' go ALTER TABLE "pears"."vacancy" ADD NOT NULL FOREIGN KEY "department" ("departmentid" ASC) REFERENCES "pears"."Department" ("departmentid") go ALTER TABLE "pears"."vacancy" ADD NOT NULL FOREIGN KEY "employment" ("employmentid" ASC) REFERENCES "pears"."employment" ("employmentid") go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "staff" ("staffid" ASC) REFERENCES "pears"."staff" ("staffid") go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "vacancyclass" ("classcode" ASC) REFERENCES "pears"."vacancyclass" ("classcode") go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "TempDesk" ("TempDeskID" ASC) REFERENCES "pears"."tempdesk" ("tempdeskid") go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "person" ("RecipientID" ASC) REFERENCES "pears"."Person" ("personid") ON DELETE SET NULL go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "TempPriceList" ("PriceListID" ASC) REFERENCES "pears"."TempPriceList" ("TempPriceListID") ON DELETE SET NULL go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "TempJobType" ("TempJobTypeID" ASC) REFERENCES "pears"."TempJobType" ("TempJobTypeID") ON DELETE SET NULL go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "origin" ("OriginID" ASC) REFERENCES "pears"."Origin" ("OriginID") go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "ComplianceDomain" ("ComplianceDomainID" ASC) REFERENCES "pears"."ComplianceDomain" ("ComplianceDomainID") ON DELETE SET NULL go ALTER TABLE "pears"."vacancy" ADD FOREIGN KEY "iqacdocumenttemplate" ("documenttemplateid" ASC) REFERENCES "pears"."IQacDocumentTemplate" ("DocumentTemplateID") ON DELETE SET NULL go CREATE INDEX "vacancy_entrydate" ON "pears"."vacancy" ( "entrydate" DESC ) go CREATE INDEX "vacancy_refcode" ON "pears"."vacancy" ( "refcode" ) go CREATE INDEX "vacancy_extnumber" ON "pears"."vacancy" ( "ExtNumber" ) go CREATE INDEX "vacancy_transferbatch" ON "pears"."vacancy" ( "TransferBatch" ) go CREATE INDEX "vacancy_status" ON "pears"."vacancy" ( "status" ) go CREATE INDEX "person_lastcontactevent" ON "pears"."vacancy" ( "lastcontactevent" DESC ) go CREATE INDEX "vacancy_desk_status" ON "pears"."vacancy" ( "TempDeskID","status" ) go CREATE INDEX "VacancyWhenEntered" ON "pears"."vacancy" ( "WhenEntered" ) go CREATE TEXT INDEX "vacancy_notestext" ON "pears"."vacancy" ( "notes","othernotes" ) CONFIGURATION "SYS"."default_char" IMMEDIATE REFRESH go create trigger "VacancyFinal" after update of "Status" order 1 on "pears"."vacancy" referencing old as "OldVac" new as "NewVac" for each row when((select first "isnull"("Status"."Final",0) from "Status" where "type" = 'V' and "NewVac"."Status" = "Status"."Status") = 1 and(select first "isnull"("Status"."Final",0) from "Status" where "type" = 'V' and "OldVac"."Status" = "Status"."Status") = 0) begin update "vacancy" set "Vacancy"."DateBecameFinal" = current date where "NewVac"."VacancyID" = "VacancyID" end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."VacancyFinal" IS {create trigger VacancyFinal after update of Status order 1 on pears.vacancy referencing old as OldVac new as NewVac for each row when((select first isnull(Status.Final,0) from Status where type = 'V' and NewVac.Status = Status.Status) = 1 and (select first isnull(Status.Final,0) from Status where type = 'V' and OldVac.Status = Status.Status) = 0) begin update vacancy set Vacancy.DateBecameFinal = current date where NewVac.VacancyID = VacancyID end } go create trigger "VacancyNoLongerFinal" after update of "Status" order 2 on "pears"."vacancy" referencing old as "OldVac" new as "NewVac" for each row when((select first "isnull"("Status"."Final",0) from "Status" where "type" = 'V' and "NewVac"."Status" = "Status"."Status") = 0 and(select first "isnull"("Status"."Final",0) from "Status" where "type" = 'V' and "OldVac"."Status" = "Status"."Status") = 1) begin update "vacancy" set "Vacancy"."DateBecameFinal" = null where "VacancyID" = "NewVac"."VacancyID" end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."VacancyNoLongerFinal" IS {create trigger VacancyNoLongerFinal after update of Status order 2 on pears.vacancy referencing old as OldVac new as NewVac for each row when((select first isnull(Status.Final,0) from Status where type = 'V' and NewVac.Status = Status.Status) = 0 and (select first isnull(Status.Final,0) from Status where type = 'V' and OldVac.Status = Status.Status) = 1) begin update vacancy set Vacancy.DateBecameFinal = null where VacancyID = NewVac.VacancyID end } go create trigger "vacancy_lsmupd" before update of "TheirRef" order 2 on "pears"."vacancy" referencing new as "new_vac" for each row when("new_vac"."transferbatch" > 0) begin set "new_vac"."transferbatch" = 0 end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."vacancy_lsmupd" IS {create trigger vacancy_lsmupd before update of TheirRef order 2 on pears.vacancy referencing new as new_vac for each row when(new_vac.transferbatch > 0) begin set new_vac.transferbatch=0 end } go create trigger "vacancy_insert" before insert order 1 on "pears"."vacancy" referencing new as "new_vacancy" for each row begin declare "autonumvacs" smallint; declare "lastvacnum" integer; set "new_vacancy"."contractref" = "trim"("new_vacancy"."contractref"); set "new_vacancy"."refcode" = "trim"("new_vacancy"."refcode"); set "new_vacancy"."sitename" = "trim"("new_vacancy"."sitename"); set "new_vacancy"."position" = "trim"("new_vacancy"."position"); set "new_vacancy"."theirref" = "trim"("new_vacancy"."theirref"); if "new_vacancy"."refcode" is null then select "autovacnumber","nextvacnumber" into "autonumvacs","lastvacnum" from "params"; if "isnull"("autonumvacs",0) <> 0 then set "new_vacancy"."refcode" = "isnull"("lastvacnum",0)+1; update "params" set "nextvacnumber" = "isnull"("nextvacnumber",0)+1 end if end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."vacancy_insert" IS {create trigger vacancy_insert before insert order 1 on pears.vacancy referencing new as new_vacancy for each row begin declare autonumvacs smallint; declare lastvacnum integer; set new_vacancy.contractref = trim(new_vacancy.contractref); set new_vacancy.refcode = trim(new_vacancy.refcode); set new_vacancy.sitename = trim(new_vacancy.sitename); set new_vacancy.position = trim(new_vacancy.position); set new_vacancy.theirref = trim(new_vacancy.theirref); if new_vacancy.refcode is null then select autovacnumber,nextvacnumber into autonumvacs,lastvacnum from params; if isnull(autonumvacs,0) <> 0 then set new_vacancy.refcode=isnull(lastvacnum,0)+1; update params set nextvacnumber = isnull(nextvacnumber,0)+1 end if end if end } go create trigger "VacancyAudit" before update of "employmentid", "departmentid","staffid","expiry","entrydate","status","startdate","salary","position","noofposts","FinishDate", "TempDeskID","RefCode","TheirRef","Payrollidentifier","othernotes","nottaxable","extranotes","sitename","siteemail","addr1","addr2","addr3","postcode","sitecontact","town","county","country","documenttemplateid" order 6 on "pears"."vacancy" referencing old as "old_vac" new as "new_vac" for each row when(exists(select * from "AuditItems" where "AreaName" = 'Vacancy' and "AuditFlag" = 1)) begin declare @AuditList long varchar; declare @OldDescrip char(250); declare @NewDescrip char(250); declare @CompName char(250); declare @CRLF char(2); set @CRLF = "char"(10)+"char"(13); select "string"(',',"list"("ItemName"),',') into @AuditList from "AuditItems" where(("AreaName" = 'Company Contact' and "AuditFlag" = 1) or("AreaName" = 'Vacancy' and "AuditFlag" = 1)); set @CompName = (select "string"("Company"."Name",' - ',"old_vac"."position",'(',"old_vac"."RefCode",')') from "Company" key join "Employment" where "Employment"."EmploymentID" = "old_vac"."EmploymentID"); -- Status if "locate"(@AuditList,',Status,') > 0 and update("Status") then select "name" into @OldDescrip from "status" where "type" = 'V' and "status"."status" = "old_vac"."status"; select "name" into @NewDescrip from "status" where "type" = 'V' and "status"."status" = "new_vac"."status"; call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Status Updated - ',@CompName),"string"("old_vac"."Status",' - ',@OldDescrip),"string"("new_vac"."Status",' - ',@NewDescrip)) end if; -- Salary if "locate"(@AuditList,',Salary,') > 0 and update("Salary") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Salary Updated - ',@CompName),"string"("old_vac"."Salary"),"string"("new_vac"."Salary")) end if; -- Position if "locate"(@AuditList,',Position,') > 0 and update("Position") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Position Updated - ',@CompName),"string"("old_vac"."Position"),"string"("new_vac"."Position")) end if; -- No of Posts if "locate"(@AuditList,',No Of Posts,') > 0 and update("NoOfPosts") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('No of Posts Updated - ',@CompName),"string"("old_vac"."NoOfPosts"),"string"("new_vac"."NoOfPosts")) end if; -- DATES if "locate"(@AuditList,',Dates,') > 0 then if update("entrydate") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Entry Date Updated - ',@CompName),"string"("old_vac"."entrydate"),"string"("new_vac"."entrydate")) end if; if update("startdate") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Start Date Updated - ',@CompName),"string"("old_vac"."startdate"),"string"("new_vac"."startdate")) end if; if update("finishdate") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Finish Date Updated - ',@CompName),"string"("old_vac"."finishdate"),"string"("new_vac"."finishdate")) end if; if update("expiry") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Expiry Date Updated - ',@CompName),"string"("old_vac"."expiry"),"string"("new_vac"."expiry")) end if end if; -- Consultant if "locate"(@AuditList,',Consultant,') > 0 and update("StaffID") then select "userid" into @OldDescrip from "staff" where "staffid" = "old_vac"."StaffID"; select "userid" into @NewDescrip from "staff" where "staffid" = "new_vac"."StaffID"; call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Consultant Updated - ',@CompName),@OldDescrip,@NewDescrip); insert into "staffhistory"( "staffhistoryid","vacancyid","oldstaff","newstaff","whenentered" ) values( "uniquekey"("new_vac"."StaffID"),"new_vac"."vacancyid","old_vac"."StaffID","new_vac"."StaffID",current timestamp ) end if; -- Department if "locate"(@AuditList,',Department,') > 0 and update("DepartmentID") then select "name" into @OldDescrip from "Department" where "DepartmentID" = "old_vac"."DepartmentID"; select "name" into @NewDescrip from "Department" where "DepartmentID" = "new_vac"."DepartmentID"; call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Department Updated - ',@CompName),@OldDescrip,@NewDescrip) end if; -- TempDesk if "locate"(@AuditList,',Temp Desk,') > 0 and update("TempDeskID") then select "name" into @OldDescrip from "TempDesk" where "TempDeskid" = "old_vac"."TempDeskID"; select "name" into @NewDescrip from "TempDesk" where "TempDeskid" = "new_vac"."TempDeskID"; call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('TempDesk Updated - ',@CompName),@OldDescrip,@NewDescrip) end if; -- Our Ref if "locate"(@AuditList,',Our Ref,') > 0 and update("RefCode") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Our Ref Updated - ',@CompName),"string"("old_vac"."RefCode"),"string"("new_vac"."RefCode")) end if; -- Payrollidentifier if "locate"(@AuditList,',Payroll Identifier,') > 0 and update("Payrollidentifier") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Payroll Identifier Updated - ',@CompName),"string"("old_vac"."Payrollidentifier"),"string"("new_vac"."Payrollidentifier")) end if; -- ExtraNotes if "locate"(@AuditList,',Extra Notes,') > 0 and update("ExtraNotes") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Extra Notes Updated - ',@CompName),"string"("old_vac"."ExtraNotes"),"string"("new_vac"."ExtraNotes")) end if; -- OtherNotes if "locate"(@AuditList,',Job Description,') > 0 and update("OtherNotes") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Job Description Ref Updated - ',@CompName),"string"("old_vac"."OtherNotes"),"string"("new_vac"."OtherNotes")) end if; -- Site Details if "locate"(@AuditList,',Site Details,') > 0 and(update("country") or update("county") or update("town") or update("sitecontact") or update("postcode") or update("addr1") or update("addr2") or update("addr3") or update("siteemail") or update("sitename")) then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Site Details Updated - ',@CompName), "string"("old_vac"."sitename",@CRLF,"old_vac"."sitecontact",@CRLF,"old_vac"."addr1",@CRLF,"old_vac"."addr2",@CRLF,"old_vac"."addr3",@CRLF,"old_vac"."town",@CRLF,"old_vac"."county",@CRLF,"old_vac"."country",@CRLF,"old_vac"."postcode",@CRLF,"old_vac"."siteemail"), "string"("new_vac"."sitename",@CRLF,"new_vac"."sitecontact",@CRLF,"new_vac"."addr1",@CRLF,"new_vac"."addr2",@CRLF,"new_vac"."addr3",@CRLF,"new_vac"."town",@CRLF,"new_vac"."county",@CRLF,"new_vac"."country",@CRLF,"new_vac"."postcode",@CRLF,"new_vac"."siteemail")) end if; -- Their Ref if "locate"(@AuditList,',Their Ref,') > 0 and update("TheirRef") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Their Ref Updated - ',@CompName),"string"("old_vac"."TheirRef"),"string"("new_vac"."TheirRef")) end if; if "locate"(@AuditList,',Override IR35 Public Sector,') > 0 and update("nottaxable") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid","string"('Override IR35 Public Sector - ',@CompName),"old_vac"."nottaxable","new_vac"."nottaxable") end if; -- Contact if "locate"(@AuditList,',Contact,') > 0 and update("employmentid") then call "AuditLog"('VACANCY',"old_VAC"."vacancyid",'Contact left company - vacancies reassigned', (select "p"."name" from "employment" as "e" key join "person" as "p" where "e"."employmentid" = "old_vac"."employmentid"),(select "p"."name" from "employment" as "e" key join "person" as "p" where "e"."employmentid" = "new_vac"."employmentid")) end if; if "locate"(@AuditList,',Contact Left Company,') > 0 and update("employmentid") then call "AuditLog"('COMPANY',(select "c"."Companyid" from "Company" as "c" key join "employment" as "e" where "e"."employmentid" = "old_VAC"."employmentid"),'Contact left company - Vacancies reassigned', (select "p"."name" from "employment" as "e" key join "person" as "p" where "e"."employmentid" = "old_vac"."employmentid"),(select "p"."name" from "employment" as "e" key join "person" as "p" where "e"."employmentid" = "new_vac"."employmentid")) end if; -- Override Invoice Layout if "locate"(@AuditList,',Override Invoice Layout,') > 0 and update("documenttemplateid") then set @OldDescrip = (select "name" from "iqacdocumenttemplate" where "documenttemplateid" = "old_vac"."documenttemplateid"); set @NewDescrip = (select "name" from "iqacdocumenttemplate" where "documenttemplateid" = "new_vac"."documenttemplateid"); call "AuditLog"('VACANCY',"old_vac"."VacancyID","string"('Override Invoice Layout Updated - ',@CompName),@OldDescrip,@NewDescrip) end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."VacancyAudit" IS {create trigger VacancyAudit before update of employmentid,departmentid,staffid,expiry,entrydate,status,startdate,salary,position,noofposts,FinishDate, TempDeskID,RefCode,TheirRef,Payrollidentifier,othernotes,nottaxable,extranotes,sitename,siteemail,addr1,addr2,addr3,postcode,sitecontact,town,county,country,documenttemplateid order 6 on pears.vacancy referencing old as old_vac new as new_vac for each row when(exists(select* from AuditItems where AreaName = 'Vacancy' and AuditFlag = 1)) begin declare @AuditList long varchar; declare @OldDescrip char(250); declare @NewDescrip char(250); declare @CompName char(250); declare @CRLF char(2); set @CRLF = "char"(10)+"char"(13); select string(',',list(ItemName),',') into @AuditList from AuditItems where (AreaName = 'Company Contact' and AuditFlag = 1) or (AreaName = 'Vacancy' and AuditFlag = 1); set @CompName=(select string(Company.Name,' - ',old_vac.position,'(',old_vac.RefCode,')') from Company key join Employment where Employment.EmploymentID = old_vac.EmploymentID); -- Status if locate(@AuditList,',Status,') > 0 and update(Status) then select name into @OldDescrip from status where type = 'V' and status.status = old_vac.status; select name into @NewDescrip from status where type = 'V' and status.status = new_vac.status; call AuditLog('VACANCY',old_VAC.vacancyid,string('Status Updated - ',@CompName),string(old_vac.Status,' - ',@OldDescrip),string(new_vac.Status,' - ',@NewDescrip)) end if; -- Salary if locate(@AuditList,',Salary,') > 0 and update(Salary) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Salary Updated - ',@CompName),string(old_vac.Salary),string(new_vac.Salary)) end if; -- Position if locate(@AuditList,',Position,') > 0 and update(Position) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Position Updated - ',@CompName),string(old_vac.Position),string(new_vac.Position)) end if; -- No of Posts if locate(@AuditList,',No Of Posts,') > 0 and update(NoOfPosts) then call AuditLog('VACANCY',old_VAC.vacancyid,string('No of Posts Updated - ',@CompName),string(old_vac.NoOfPosts),string(new_vac.NoOfPosts)) end if; -- DATES if locate(@AuditList,',Dates,') > 0 then if update(entrydate) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Entry Date Updated - ',@CompName),string(old_vac.entrydate),string(new_vac.entrydate)) end if; if update(startdate) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Start Date Updated - ',@CompName),string(old_vac.startdate),string(new_vac.startdate)) end if; if update(finishdate) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Finish Date Updated - ',@CompName),string(old_vac.finishdate),string(new_vac.finishdate)) end if; if update(expiry) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Expiry Date Updated - ',@CompName),string(old_vac.expiry),string(new_vac.expiry)) end if end if; -- Consultant if locate(@AuditList,',Consultant,') > 0 and update(StaffID) then select userid into @OldDescrip from staff where staffid = old_vac.StaffID; select userid into @NewDescrip from staff where staffid = new_vac.StaffID; call AuditLog('VACANCY',old_VAC.vacancyid,string('Consultant Updated - ',@CompName),@OldDescrip,@NewDescrip); insert into staffhistory (staffhistoryid, vacancyid, oldstaff, newstaff, whenentered) values (uniquekey(new_vac.StaffID),new_vac.vacancyid, old_vac.StaffID, new_vac.StaffID, current timestamp) end if; -- Department if locate(@AuditList,',Department,') > 0 and update(DepartmentID) then select name into @OldDescrip from Department where DepartmentID = old_vac.DepartmentID; select name into @NewDescrip from Department where DepartmentID = new_vac.DepartmentID; call AuditLog('VACANCY',old_VAC.vacancyid,string('Department Updated - ',@CompName),@OldDescrip,@NewDescrip) end if; -- TempDesk if locate(@AuditList,',Temp Desk,') > 0 and update(TempDeskID) then select name into @OldDescrip from TempDesk where TempDeskid = old_vac.TempDeskID; select name into @NewDescrip from TempDesk where TempDeskid = new_vac.TempDeskID; call AuditLog('VACANCY',old_VAC.vacancyid,string('TempDesk Updated - ',@CompName),@OldDescrip,@NewDescrip) end if; -- Our Ref if locate(@AuditList,',Our Ref,') > 0 and update(RefCode) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Our Ref Updated - ',@CompName),string(old_vac.RefCode),string(new_vac.RefCode)) end if; -- Payrollidentifier if locate(@AuditList,',Payroll Identifier,') > 0 and update(Payrollidentifier) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Payroll Identifier Updated - ',@CompName),string(old_vac.Payrollidentifier),string(new_vac.Payrollidentifier)) end if; -- ExtraNotes if locate(@AuditList,',Extra Notes,') > 0 and update(ExtraNotes) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Extra Notes Updated - ',@CompName),string(old_vac.ExtraNotes),string(new_vac.ExtraNotes)) end if; -- OtherNotes if locate(@AuditList,',Job Description,') > 0 and update(OtherNotes) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Job Description Ref Updated - ',@CompName),string(old_vac.OtherNotes),string(new_vac.OtherNotes)) end if; -- Site Details if locate(@AuditList,',Site Details,') > 0 and (update(country) or update(county) or update(town) or update(sitecontact) or update(postcode)or update(addr1)or update(addr2)or update(addr3)or update(siteemail)or update(sitename)) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Site Details Updated - ',@CompName), string(old_vac.sitename,@CRLF,old_vac.sitecontact,@CRLF,old_vac.addr1,@CRLF,old_vac.addr2,@CRLF,old_vac.addr3,@CRLF,old_vac.town,@CRLF,old_vac.county,@CRLF,old_vac.country,@CRLF,old_vac.postcode,@CRLF,old_vac.siteemail), string(new_vac.sitename,@CRLF,new_vac.sitecontact,@CRLF,new_vac.addr1,@CRLF,new_vac.addr2,@CRLF,new_vac.addr3,@CRLF,new_vac.town,@CRLF,new_vac.county,@CRLF,new_vac.country,@CRLF,new_vac.postcode,@CRLF,new_vac.siteemail)) end if; -- Their Ref if locate(@AuditList,',Their Ref,') > 0 and update(TheirRef) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Their Ref Updated - ',@CompName),string(old_vac.TheirRef),string(new_vac.TheirRef)) end if; if locate(@AuditList,',Override IR35 Public Sector,') > 0 and update(nottaxable) then call AuditLog('VACANCY',old_VAC.vacancyid,string('Override IR35 Public Sector - ',@CompName),old_vac.nottaxable,new_vac.nottaxable) end if; -- Contact if locate(@AuditList,',Contact,') > 0 and update(employmentid) then call AuditLog('VACANCY',old_VAC.vacancyid,'Contact left company - vacancies reassigned', (select p.name from employment as e key join person as p where e.employmentid = old_vac.employmentid),(select p.name from employment as e key join person as p where e.employmentid = new_vac.employmentid)) end if; if locate(@AuditList,',Contact Left Company,') > 0 and update(employmentid) then call AuditLog('COMPANY',(select c.Companyid from Company as c key join employment as e where e.employmentid = old_VAC.employmentid),'Contact left company - Vacancies reassigned', (select p.name from employment as e key join person as p where e.employmentid = old_vac.employmentid),(select p.name from employment as e key join person as p where e.employmentid = new_vac.employmentid)) end if; -- Override Invoice Layout if locate(@AuditList,',Override Invoice Layout,') > 0 and update(documenttemplateid) then set @OldDescrip=(select name from iqacdocumenttemplate where documenttemplateid = old_vac.documenttemplateid); set @NewDescrip=(select name from iqacdocumenttemplate where documenttemplateid = new_vac.documenttemplateid); call AuditLog('VACANCY',old_vac.VacancyID,string('Override Invoice Layout Updated - ',@CompName),@OldDescrip,@NewDescrip) end if; end } go create trigger "vacancy_insert2" after insert order 1 on "pears"."vacancy" referencing new as "new_vacancy" for each row begin declare "rateschemeid" char(20); declare "dynam" integer; if "new_vacancy"."temp" = 1 and "new_vacancy"."tempjobtypeid" is null then select "t"."tempjobtypeid","isnull"("t"."dynamic",0) into "rateschemeid","dynam" from "tempjobtype" as "t" join "company" as "c" on "c"."defaultratescheme" = "t"."tempjobtypeid" key join "employment" as "e" where "e"."employmentid" = "new_vacancy"."employmentid" and "t"."secondaryagencyid" is null and("string"(',',"c"."tempchargecode",',') like "string"('%,',"t"."clienttempchargecode",',%') or "t"."clienttempchargecode" is null) and("t"."DepartmentID" = "new_vacancy"."departmentid" or "t"."departmentid" is null); if "rateschemeid" is null then select "t"."tempjobtypeid","isnull"("t"."dynamic",0) into "rateschemeid","dynam" from "tempjobtype" as "t","company" as "c" key join "employment" as "e" where "e"."employmentid" = "new_vacancy"."employmentid" and "t"."secondaryagencyid" is null and "t"."description" like 'Global Default%' and("string"(',',"c"."tempchargecode",',') like "string"('%,',"t"."clienttempchargecode",',%') or "t"."clienttempchargecode" is null) and("t"."DepartmentID" = "new_vacancy"."departmentid" or "t"."departmentid" is null) end if; if "rateschemeid" is not null then update "vacancy" set "tempjobtypeid" = "rateschemeid" where "vacancyid" = "new_vacancy"."vacancyid"; if "dynam" = 0 then insert into "tempjobrate"( "ChargeRate","EndDate","Grade","PayRate","StartDate","TempJobRateID","TempPayBandID","VacancyID" ) ( select "ChargeRate","EndDate","Grade","PayRate","StartDate","uniquekey"("tempjobratemasterid"),"TempPayBandID","new_vacancy"."vacancyid" from "tempjobratemaster" where "tempjobtypeid" = "rateschemeid") end if end if end if; if "new_vacancy"."temp" = 1 and "wpkmaintaingetswitchvalue"('AWRVISIBLE','','L') = 'Y' then insert into "AWRvacancy"( "vacancyid","AWRStatus","benefits","notes","holidays","pay","bonus","extrahols" ) select "new_vacancy"."vacancyid", "AWRStatus","benefits","notes","holidays","pay","bonus","extrahols" from "AWRcompany" where "companyid" = (select "companyid" from "employment" where "employmentid" = "new_vacancy"."employmentid") end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."vacancy_insert2" IS {create trigger vacancy_insert2 after insert order 1 on "pears"."vacancy" referencing new as "new_vacancy" for each row begin declare "rateschemeid" char(20); declare "dynam" integer; if "new_vacancy"."temp" = 1 and "new_vacancy"."tempjobtypeid" is null then select "t"."tempjobtypeid","isnull"("t"."dynamic",0) into "rateschemeid","dynam" from "tempjobtype" as "t" join "company" as "c" on "c"."defaultratescheme" = "t"."tempjobtypeid" key join "employment" as "e" where "e"."employmentid" = "new_vacancy"."employmentid" and "t"."secondaryagencyid" is null and("string"(',',"c"."tempchargecode",',') like "string"('%,',"t"."clienttempchargecode",',%') or "t"."clienttempchargecode" is null) and("t"."DepartmentID" = "new_vacancy"."departmentid" or "t"."departmentid" is null); if "rateschemeid" is null then select "t"."tempjobtypeid","isnull"("t"."dynamic",0) into "rateschemeid","dynam" from "tempjobtype" as "t","company" as "c" key join "employment" as "e" where "e"."employmentid" = "new_vacancy"."employmentid" and "t"."secondaryagencyid" is null and "t"."description" like 'Global Default%' and("string"(',',"c"."tempchargecode",',') like "string"('%,',"t"."clienttempchargecode",',%') or "t"."clienttempchargecode" is null) and("t"."DepartmentID" = "new_vacancy"."departmentid" or "t"."departmentid" is null) end if; if "rateschemeid" is not null then update "vacancy" set "tempjobtypeid" = "rateschemeid" where "vacancyid" = "new_vacancy"."vacancyid"; if "dynam" = 0 then insert into "tempjobrate"( "ChargeRate","EndDate","Grade","PayRate","StartDate","TempJobRateID","TempPayBandID","VacancyID" ) ( select "ChargeRate","EndDate","Grade","PayRate","StartDate","uniquekey"("tempjobratemasterid"),"TempPayBandID","new_vacancy"."vacancyid" from "tempjobratemaster" where "tempjobtypeid" = "rateschemeid") end if end if end if; if "new_vacancy"."temp" = 1 and "wpkmaintaingetswitchvalue"('AWRVISIBLE','','L') = 'Y' then insert into "AWRvacancy"( "vacancyid","AWRStatus","benefits","notes","holidays","pay","bonus","extrahols" ) select "new_vacancy"."vacancyid", "AWRStatus","benefits","notes","holidays","pay","bonus","extrahols" from "AWRcompany" where "companyid" = (select "companyid" from "employment" where "employmentid" = "new_vacancy"."employmentid") end if end } go create trigger "vacancy_delete" before delete order 1 on "pears"."vacancy" referencing old as "old_vacancy" for each row begin update "person" set "ExclusiveVacancyID" = null where "ExclusiveVacancyID" = "old_vacancy"."vacancyid" end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."vacancy_delete" IS {create trigger vacancy_delete before delete order 1 on pears.vacancy referencing old as old_vacancy for each row begin update person set ExclusiveVacancyID = null where ExclusiveVacancyID = old_vacancy.vacancyid end } go create trigger "psHealthVacancyUpdate" after update of "recipientid" order 900 on "pears"."vacancy" referencing new as "new_rec" for each row begin if "psHealthCanSendVacancy"("new_rec"."vacancyid") = 1 then call "psHealthInsertUpdateVacancy"("new_rec"."vacancyid") end if end go create trigger "vacancy_UpdateTrim" before update order 7 on "pears"."vacancy" referencing new as "new_vacancy" for each row begin set "new_vacancy"."contractref" = "trim"("new_vacancy"."contractref"); set "new_vacancy"."refcode" = "trim"("new_vacancy"."refcode"); set "new_vacancy"."sitename" = "trim"("new_vacancy"."sitename"); set "new_vacancy"."position" = "trim"("new_vacancy"."position"); set "new_vacancy"."theirref" = "trim"("new_vacancy"."theirref") end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."vacancy_UpdateTrim" IS {create trigger vacancy_UpdateTrim before update order 7 on pears.vacancy referencing new as new_vacancy for each row begin set new_vacancy.contractref = trim(new_vacancy.contractref); set new_vacancy.refcode = trim(new_vacancy.refcode); set new_vacancy.sitename = trim(new_vacancy.sitename); set new_vacancy.position = trim(new_vacancy.position); set new_vacancy.theirref = trim(new_vacancy.theirref) end } go create trigger "InsertStatusVacancy" after insert order 2 on "pears"."Vacancy" referencing new as "new_co" for each row begin insert into "StatusHistory"( "StatusHistoryID","Vacancyid","staffid","newstatus" ) values ( "uniquekey"("new_co"."Vacancyid"),"new_co"."Vacancyid","userstaffid","new_co"."status" ) end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."InsertStatusVacancy" IS {create trigger InsertStatusVacancy after insert order 2 on pears.Vacancy referencing new as new_co for each row begin insert into StatusHistory (StatusHistoryID, Vacancyid, staffid, newstatus) values (uniquekey(new_co.Vacancyid),new_co.Vacancyid, userstaffid,new_co.status) end } go create trigger "UpdateStatusVacancy" after update of "status" order 3 on "pears"."Vacancy" referencing old as "old_co" new as "new_co" for each row begin declare "ID" char(20); select first "StatusHistoryID" into "ID" from "StatusHistory" where "Vacancyid" = "new_co"."Vacancyid" and "datediff"("minute","whenentered",current timestamp) < 1 and "newstatus" = "old_co"."status" and "oldstatus" = "new_co"."status" order by "whenentered" desc; if "ID" is not null then delete from "StatusHistory" where "StatusHistoryID" = "ID" else insert into "StatusHistory"( "StatusHistoryID","Vacancyid","staffid","oldstatus","newstatus" ) values ( "uniquekey"("new_co"."Vacancyid"),"new_co"."Vacancyid","userstaffid","old_co"."status","new_co"."status" ) end if end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."UpdateStatusVacancy" IS {create trigger UpdateStatusVacancy after update of status order 3 on pears.Vacancy referencing old as old_co new as new_co for each row begin declare ID char(20); select first StatusHistoryID into ID from StatusHistory where Vacancyid = new_co.Vacancyid and datediff(minute, whenentered, current timestamp) < 1 and newstatus = old_co.status and oldstatus = new_co.status order by whenentered desc; if ID is not null then delete from StatusHistory where StatusHistoryID = ID else insert into StatusHistory (StatusHistoryID, Vacancyid, staffid, oldstatus, newstatus) values (uniquekey(new_co.Vacancyid),new_co.Vacancyid, userstaffid, old_co.status, new_co.status) end if; end } go create trigger "VacancyKeyWordsInsert" after insert order 20 on "pears"."vacancy" referencing new as "NewRow" for each row begin insert into "VacancyKeyWords"( "VacancyID","RefreshRequired" ) on existing update defaults off values( "NewRow"."VacancyID",1 ) end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."VacancyKeyWordsInsert" IS {create trigger VacancyKeyWordsInsert after insert order 20 on pears.vacancy referencing new as NewRow for each row begin insert into VacancyKeyWords(VacancyID,RefreshRequired) on existing update values(NewRow.VacancyID,1); end } go create trigger "VacancyKeyWordsUpdate" after update of "refcode", "position","siteemail","sitename","sitecontact","employmentid" order 21 on "pears"."Vacancy" referencing new as "NewRow" for each row begin update "VacancyKeyWords" set "RefreshRequired" = 1 where "VacancyID" = "NewRow"."VacancyID" end go COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."vacancy"."VacancyKeyWordsUpdate" IS {create trigger VacancyKeyWordsUpdate after update of refcode, position, siteemail, sitename, sitecontact, employmentid order 21 on pears.Vacancy referencing new as NewRow for each row begin update VacancyKeyWords set RefreshRequired = 1 where VacancyID = NewRow.VacancyID; end } go </code> database/tables/pears_vacancy.txt Last modified: 2026/08/07 19:24by 127.0.0.1