====== pears.AWRcompany ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Description =====
AWR settings for Company records. One-to-one relationship with Company table.
===== Columns =====
^ Column ^ Type ^ Null ^ Default ^ Comment ^
| **companyid** | char(20) | NOT NULL | | |
| AWRStatus | smallint | NOT NULL | 1 | |
| pay | long varchar | NULL | | |
| holidays | long varchar | NULL | | |
| benefits | long varchar | NULL | | |
| notes | long varchar | NULL | | |
| bonus | long varchar | NULL | | |
| extrahols | double | NULL | | |
| LECode | char(50) | NULL | | |
| AWRCheckDate | date | NULL | | |
===== Primary Key =====
* companyid
===== Foreign Keys =====
^ Constraint ^ Columns ^ References ^ Delete/update action ^
| Company | companyid | [[database:tables:pears_company|pears.Company (companyid)]] | NOT NULL; ON DELETE CASCADE |
===== Referenced By =====
* No incoming foreign keys found.
===== Indexes =====
* No indexes found.
===== Triggers =====
^ Name ^ Timing ^ Event ^
| AWRcompany_update | after | update of "AWRStatus", "AWRCheckDate", "LECode" order 1 |
| AWRCompany_Insert | before | insert order 1 |
| AWRCompany_UpdateTrim | before | update order 2 |
===== Original SQL =====
-- IQX database structure split by table
-- Source: IQXDatabaseStructure - with comments.sql
-- Table: "pears"."AWRcompany"
-- Table comment: AWR settings for Company records. One-to-one relationship with Company table.
-- Statement count: 9
CREATE TABLE "pears"."AWRcompany" (
"companyid" char(20) NOT NULL
,"AWRStatus" smallint NOT NULL DEFAULT 1
,"pay" long varchar NULL
,"holidays" long varchar NULL
,"benefits" long varchar NULL
,"notes" long varchar NULL
,"bonus" long varchar NULL
,"extrahols" double NULL
,"LECode" char(50) NULL
,"AWRCheckDate" date NULL
,PRIMARY KEY ("companyid" ASC)
)
go
COMMENT ON TABLE "pears"."AWRcompany" IS
'AWR settings for Company records. One-to-one relationship with Company table.'
go
ALTER TABLE "pears"."AWRcompany"
ADD NOT NULL FOREIGN KEY "Company" ("companyid" ASC)
REFERENCES "pears"."Company" ("companyid")
ON DELETE CASCADE
go
create trigger "AWRcompany_update" after update of "AWRStatus",
"AWRCheckDate",
"LECode" order 1 on "pears"."AWRcompany"
referencing old as "old_awr" new as "new_awr"
for each row
begin
declare @CompName char(250);
set @CompName = (select "Name" from "company" where "companyid" = "old_awr"."companyID");
-- audit
if update("AWRStatus") then
call "AuditLog"('AWRCOMP',"old_awr"."companyID",
"string"('AWR Status Company - ',@CompName),case "old_awr"."AWRStatus" when 1 then 'Not Known' when 2 then 'AWR Applies' when 3 then 'AWR not Applicable' end,
case "new_awr"."AWRStatus" when 1 then 'Not Known' when 2 then 'AWR Applies' when 3 then 'AWR not Applicable' end)
end if;
if update("LECode") then
call "AuditLog"('AWRCOMP',"old_awr"."companyID",
"string"('AWR LE Code Company - ',@CompName),"old_awr"."LECode","new_awr"."LECode")
end if;
if update("AWRCheckDate") then
call "AuditLog"('AWRCOMP',"old_awr"."companyID",
"string"('AWR Checked Date Company - ',@CompName),"string"("old_awr"."AWRCheckDate"),"string"("new_awr"."AWRCheckDate"))
end if
end
go
COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."AWRcompany"."AWRcompany_update" IS
{create trigger AWRcompany_update
after update of AWRStatus,
AWRCheckDate,
LECode order 1 on pears.AWRcompany
referencing old as old_awr new as new_awr
for each row
begin
declare @CompName char(250);
set @CompName=(select Name from company where companyid = old_awr.companyID);
-- audit
if update(AWRStatus) then
call AuditLog('AWRCOMP',old_awr.companyID,
string('AWR Status Company - ',@CompName),case old_awr.AWRStatus when 1 then 'Not Known' when 2 then 'AWR Applies' when 3 then 'AWR not Applicable'
end,case new_awr.AWRStatus when 1 then 'Not Known' when 2 then 'AWR Applies' when 3 then 'AWR not Applicable'
end)
end if;
if update(LECode) then
call AuditLog('AWRCOMP',old_awr.companyID,
string('AWR LE Code Company - ',@CompName),old_awr.LECode,new_awr.LECode)
end if;
if update(AWRCheckDate) then
call AuditLog('AWRCOMP',old_awr.companyID,
string('AWR Checked Date Company - ',@CompName),string(old_awr.AWRCheckDate),string(new_awr.AWRCheckDate))
end if
end
}
go
create trigger "AWRCompany_Insert" before insert order 1 on
"pears"."AWRCompany"
referencing new as "new_awr"
for each row
begin
declare @CompName char(250);
set @CompName = (select "Name" from "company" where "companyid" = "new_awr"."companyID");
set "new_awr"."LECode" = "trim"("new_awr"."LECode");
call "AuditLog"('AWRCOMP',"new_awr"."companyID",
"string"('AWR Status Company Insert - ',@CompName),'',case "new_awr"."AWRStatus" when 1 then 'Not Known' when 2 then 'AWR Applies' when 3 then 'AWR not Applicable' end);
if "isnull"("new_awr"."LECode",'') > '' then
call "AuditLog"('AWRCOMP',"new_awr"."companyID",
"string"('AWR LE Code Company Insert - ',@CompName),'',"new_awr"."LECode")
end if;
if "new_awr"."AWRCheckDate" is not null then
call "AuditLog"('AWRCOMP',"new_awr"."companyID",
"string"('AWR Checked Date Company Insert - ',@CompName),'',"string"("new_awr"."AWRCheckDate"))
end if
end
go
COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."AWRcompany"."AWRCompany_Insert" IS
{create trigger AWRCompany_Insert
before insert order 1 on
pears.AWRCompany
referencing new as new_awr
for each row
begin
declare @CompName char(250);
set @CompName=(select Name from company where companyid = new_awr.companyID);
set new_awr.LECode = trim(new_awr.LECode);
call AuditLog('AWRCOMP',new_awr.companyID,
string('AWR Status Company Insert - ',@CompName),'',case new_awr.AWRStatus when 1 then 'Not Known' when 2 then 'AWR Applies' when 3 then 'AWR not Applicable'
end);
if isnull(new_awr.LECode,'') > '' then
call AuditLog('AWRCOMP',new_awr.companyID,
string('AWR LE Code Company Insert - ',@CompName),'',new_awr.LECode)
end if;
if new_awr.AWRCheckDate is not null then
call AuditLog('AWRCOMP',new_awr.companyID,
string('AWR Checked Date Company Insert - ',@CompName),'',string(new_awr.AWRCheckDate))
end if
end
}
go
create trigger "AWRCompany_UpdateTrim" before update order 2 on
"pears"."AWRCompany"
referencing new as "new_awr"
for each row
begin
set "new_awr"."LECode" = "trim"("new_awr"."LECode")
end
go
COMMENT TO PRESERVE FORMAT ON TRIGGER "pears"."AWRcompany"."AWRCompany_UpdateTrim" IS
{create trigger AWRCompany_UpdateTrim
before update order 2 on
pears.AWRCompany
referencing new as new_awr
for each row
begin
set new_awr.LECode = trim(new_awr.LECode);
end
}
go