CREATE TABLE [dbo].[al_costdet]
(
[cdbegdt] [datetime] NULL,
[cdivid] [smallint] NULL,
[cduntamt] [float] NULL,
[company_uuid] [binary] (16) NULL,
[cdbillcd] [bigint] NULL,
[cdcommnt] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cdreunt] [smallint] NULL,
[cdretmdt] [datetime] NULL,
[cdreact] [smallint] NULL,
[cdrecap] [smallint] NULL,
[cdreespc] [float] NULL,
[cost_center] [int] NULL,
[cdcurrty] [smallint] NULL,
[cdtype] [bigint] NULL,
[gl_code] [int] NULL,
[cdpaytype] [smallint] NULL,
[cdpaytot] [float] NULL,
[creation_user] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[creation_date] [int] NULL,
[last_update_user] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[last_update_date] [int] NULL,
[version_number] [int] NULL CONSTRAINT [DF__AL_COSTD__VERSI__05A3D694] DEFAULT ('0 '),
[cdamtper] [int] NULL,
[cdreper] [int] NULL,
[part_number] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[cost_id] [bigint] NOT NULL,
[currency_type_code] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[tenant] [binary] (16) NULL
) ON [PRIMARY]
GO
CREATE TRIGGER dbo.ca_tr_del_al_costdet
ON dbo.al_costdet
FOR DELETE AS
DECLARE
@audit_product nvarchar(64)
SET @audit_product = APP_NAME()
INSERT INTO dbo.aud_al_costdet (
AUDIT_TRAIL_PRODUCT,
AUDIT_TRAIL_USER,
AUDIT_TRAIL_TYPE,
AUDIT_TRAIL_DATE,
cdbegdt,
cdivid,
cduntamt,
company_uuid,
cdbillcd,
cdcommnt,
cdreunt,
cdretmdt,
cdreact,
cdrecap,
cdreespc,
cost_center,
cdcurrty,
cdtype,
gl_code,
cdpaytype,
cdpaytot,
creation_user,
creation_date,
last_update_user,
last_update_date,
version_number,
cdamtper,
cdreper,
part_number,
cost_id,
currency_type_code,
tenant) SELECT
@audit_product,old.last_update_user, 'DELETE', datediff(ss, '1/1/1970', getutcdate()),
old.cdbegdt,
old.cdivid,
old.cduntamt,
old.company_uuid,
old.cdbillcd,
old.cdcommnt,
old.cdreunt,
old.cdretmdt,
old.cdreact,
old.cdrecap,
old.cdreespc,
old.cost_center,
old.cdcurrty,
old.cdtype,
old.gl_code,
old.cdpaytype,
old.cdpaytot,
old.creation_user,
old.creation_date,
old.last_update_user,
old.last_update_date,
old.version_number,
old.cdamtper,
old.cdreper,
old.part_number,
old.cost_id,
old.currency_type_code,
old.tenant
FROM deleted old
GO
CREATE TRIGGER dbo.ca_tr_ins_al_costdet
ON dbo.al_costdet
FOR INSERT AS
DECLARE
@audit_product nvarchar(64)
SET @audit_product = APP_NAME()
INSERT INTO dbo.aud_al_costdet (
AUDIT_TRAIL_PRODUCT,
AUDIT_TRAIL_USER,
AUDIT_TRAIL_TYPE,
AUDIT_TRAIL_DATE,
cdbegdt,
cdivid,
cduntamt,
company_uuid,
cdbillcd,
cdcommnt,
cdreunt,
cdretmdt,
cdreact,
cdrecap,
cdreespc,
cost_center,
cdcurrty,
cdtype,
gl_code,
cdpaytype,
cdpaytot,
creation_user,
creation_date,
last_update_user,
last_update_date,
version_number,
cdamtper,
cdreper,
part_number,
cost_id,
currency_type_code,
tenant) SELECT
@audit_product, new.last_update_user, 'INSERT', datediff(ss, '1/1/1970', getutcdate()),
new.cdbegdt,
new.cdivid,
new.cduntamt,
new.company_uuid,
new.cdbillcd,
new.cdcommnt,
new.cdreunt,
new.cdretmdt,
new.cdreact,
new.cdrecap,
new.cdreespc,
new.cost_center,
new.cdcurrty,
new.cdtype,
new.gl_code,
new.cdpaytype,
new.cdpaytot,
new.creation_user,
new.creation_date,
new.last_update_user,
new.last_update_date,
new.version_number,
new.cdamtper,
new.cdreper,
new.part_number,
new.cost_id,
new.currency_type_code,
new.tenant
FROM inserted new
GO
CREATE TRIGGER dbo.ca_tr_upd_al_costdet
ON dbo.al_costdet
FOR UPDATE AS
DECLARE
@audit_product nvarchar(64),
@last_update_user nvarchar(64),
@version_number int
SET @audit_product = APP_NAME()
SELECT @version_number = version_number, @last_update_user = last_update_user FROM inserted
IF @version_number != -1
INSERT INTO dbo.aud_al_costdet (
AUDIT_TRAIL_PRODUCT,
AUDIT_TRAIL_USER,
AUDIT_TRAIL_TYPE,
AUDIT_TRAIL_DATE,
cdbegdt,
cdivid,
cduntamt,
company_uuid,
cdbillcd,
cdcommnt,
cdreunt,
cdretmdt,
cdreact,
cdrecap,
cdreespc,
cost_center,
cdcurrty,
cdtype,
gl_code,
cdpaytype,
cdpaytot,
creation_user,
creation_date,
last_update_user,
last_update_date,
version_number,
cdamtper,
cdreper,
part_number,
cost_id,
currency_type_code,
tenant) SELECT
@audit_product, new.last_update_user, 'UPDATE', datediff(ss, '1/1/1970', getutcdate()),
new.cdbegdt,
new.cdivid,
new.cduntamt,
new.company_uuid,
new.cdbillcd,
new.cdcommnt,
new.cdreunt,
new.cdretmdt,
new.cdreact,
new.cdrecap,
new.cdreespc,
new.cost_center,
new.cdcurrty,
new.cdtype,
new.gl_code,
new.cdpaytype,
new.cdpaytot,
new.creation_user,
new.creation_date,
new.last_update_user,
new.last_update_date,
new.version_number,
new.cdamtper,
new.cdreper,
new.part_number,
new.cost_id,
new.currency_type_code,
new.tenant
FROM inserted new
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [xpkal_costdet] PRIMARY KEY CLUSTERED ([cost_id]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [al_costdet_idx01] ON [dbo].[al_costdet] ([company_uuid]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDCOJOIN02] FOREIGN KEY ([company_uuid]) REFERENCES [dbo].[ca_company] ([company_uuid])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDCTJOIN02] FOREIGN KEY ([currency_type_code]) REFERENCES [dbo].[ca_currency_type] ([currency_type_code])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDDLJOIN05] FOREIGN KEY ([cdtype]) REFERENCES [dbo].[arg_dl_cost_type] ([id])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDDLJOIN06] FOREIGN KEY ([cdbillcd]) REFERENCES [dbo].[arg_dl_billing_code] ([id])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDGLCJOIN02] FOREIGN KEY ([gl_code]) REFERENCES [dbo].[ca_resource_gl_code] ([id])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDRCCJOIN02] FOREIGN KEY ([cost_center]) REFERENCES [dbo].[ca_resource_cost_center] ([id])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [CDSLJOIN06] FOREIGN KEY ([cdreunt]) REFERENCES [dbo].[arg_sl_recurring_period] ([id])
GO
ALTER TABLE [dbo].[al_costdet] ADD CONSTRAINT [FK_AL_COSTDET_TENANT] FOREIGN KEY ([tenant]) REFERENCES [dbo].[ca_tenant] ([id])
GO