UPDATE R5APPSETTINGS set AST_VALUE = '11000'
 where AST_NAME = 'CODEVERSION';
 
 UPDATE R5APPSETTINGS set AST_VALUE = '11.0.0'
 where AST_NAME = 'APPVERSION';

--Breadcrumbs new table
CREATE TABLE "R5LBSDATA" (LBS_DEVICEID VARCHAR (50) NOT NULL, LBS_DATE DATETIME NOT NULL, LBS_LATITUDE REAL NOT NULL, LBS_LONGITUDE REAL NOT NULL, LBS_USER VARCHAR(50), LBS_EMPLOYEE VARCHAR(50), LBS_OBJECT VARCHAR(50), LBS_OBJECT_ORG VARCHAR(50), LBS_EVENT VARCHAR(50), LBS_EVENT_ORG VARCHAR(50), LBS_EVENT_START DATETIME, LBS_EVENT_STOP DATETIME, DMLTYPE NCHAR(1));

--Inspection Screen Config Change
UPDATE r5configsettings  SET CFS_XMLCONFIG='{"sections":[{ "name":"Inspection", "fields":[ {"id":"EPO_OBJECT", "lbl":"Equipment", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"30", "hid":"NO" }, {"id":"EPO_ASPECT", "lbl":"Aspect", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"4", "hid":"NO" }, {"id":"EPO_POINTTYPE", "lbl":"Point Type", "type":"CHAR", "def":"", "ro":"YES", "rq":"NO", "len":"4", "hid":"NO" }, {"id":"EPO_POINT", "lbl":"Point", "type":"LOV-2", "def":"", "ro":"YES", "rq":"NO", "len":"3", "hid":"NO" }, {"id":"EPO_VALUE", "lbl":"Value", "type":"NUM", "def":"", "ro":"NO", "rq":"NO", "len":"24", "hid":"NO" }, {"id":"EPO_UOM", "lbl":"UOM", "type":"LOV-1", "def":"", "ro":"YES", "rq":"NO", "len":"15", "hid":"NO" }, {"id":"EPO_METHOD", "lbl":"Method", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"NO" }, {"id":"EPO_FINDING", "lbl":"Finding", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"4", "hid":"NO" }, {"id":"EPO_RESULT_DESC", "lbl":"Result", "type":"PICKER", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"EPO_DATE", "lbl":"Date", "type":"DATE", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"EPO_COMPLETED", "lbl":"Completed", "type":"BOOL", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"NO" }, {"id":"EPO_LOCATION", "lbl":"Location", "type":"CHAR", "def":"", "ro":"NO", "rq":"NO", "len":"70", "hid":"NO" }, {"id":"EPO_COMMENT", "lbl":"Note", "type":"CHAR", "def":"", "ro":"NO", "rq":"NO", "len":"70", "hid":"NO" }, {"id":"EPO_INSPECTOR", "lbl":"Inspector", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"15", "hid":"NO" }, {"id":"EPO_STWO", "lbl":"Standard WO", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"NO" }, {"id":"EPO_CREATE", "lbl":"New WO Required", "type":"BOOL", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"NO" }] }]}'  WHERE CFS_CODE='TCJEPO_IPAD' AND CFS_GROUP = '*';

--Issue return Screen Config Change
UPDATE r5configsettings  SET CFS_XMLCONFIG='{"sections":[{ "name":"Issue/Return", "fields":[ {"id":"TRA_ACT", "lbl":"Activity", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"3", "hid":"NO" }, {"id":"TRA_IR", "lbl":"Issue/Return", "type":"PICKER", "def":"", "ro":"NO", "rq":"YES", "len":"1", "hid":"NO" }, {"id":"TRA_OBJECT", "lbl":"Equipment", "type":"LOV-1", "def":"", "ro":"YES", "rq":"NO", "len":"30", "hid":"NO" }, {"id":"TRA_MRC", "lbl":"Department", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"15", "hid":"NO" }, {"id":"TRA_COSTCODE", "lbl":"Cost Code", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"30", "hid":"NO" }, {"id":"TRA_STORE", "lbl":"Store", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"15", "hid":"NO" }, {"id":"TRA_MATLREV", "lbl":"Material List", "type":"CHAR", "def":"", "ro":"YES", "rq":"NO", "len":"20", "hid":"NO" }] }, { "name":"Part Details", "fields":[ {"id":"TRL_PART", "lbl":"Part", "type":"LOV-2", "def":"", "ro":"NO", "rq":"YES", "len":"15", "hid":"NO" },{"id":"TRL_MANUPART", "lbl":"Manufacturer Part", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"15", "hid":"YES" }, {"id":"TRL_BIN", "lbl":"Bin", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"15", "hid":"NO" }, {"id":"TRL_LOT", "lbl":"Lot", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"12", "hid":"NO" },  {"id":"TRL_CONCODE", "lbl":"Condition", "type":"CHAR", "def":"", "ro":"YES", "rq":"NO", "len":"15", "hid":"NO" }, {"id":"TRL_RETCON", "lbl":"Return Condition", "type":"LOV-2", "def":"", "ro":"NO", "rq":"NO", "len":"15", "hid":"NO" },{"id":"TRL_AVAILQTY", "lbl":"Available Qty", "type":"NUM", "def":"", "ro":"YES", "rq":"NO", "len":"24", "hid":"NO" }, {"id":"TRL_QTY", "lbl":"Transaction Qty", "type":"NUM", "def":"", "ro":"NO", "rq":"YES", "len":"24", "hid":"NO" }, {"id":"TRL_OBJECT", "lbl":"Asset ID", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"30", "hid":"NO" }] }]}' WHERE CFS_CODE='TCJISU_IPAD' AND CFS_GROUP = '*';

--Planned part Screen Config Change
UPDATE r5configsettings  SET CFS_XMLCONFIG='{"sections":[{ "name":"Parts", "fields":[ {"id":"PAR_ACTIVITYID", "lbl":"Activity", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"24", "hid":"NO" }, {"id":"PAR_CODE", "lbl":"Part", "type":"LOV-2", "def":"", "ro":"NO", "rq":"YES", "len":"15", "hid":"NO" }, {"id":"PAR_MANUPART", "lbl":"Manufacturer Part", "type":"LOV-1", "def":"", "ro":"NO", "rq":"NO", "len":"15", "hid":"YES" }, {"id":"PAR_PARTCONDITION", "lbl":"Condition", "type":"CHAR", "def":"", "ro":"YES", "rq":"NO", "len":"15", "hid":"NO" },{"id":"PAR_PLANNEDQTY", "lbl":"Planned Qty", "type":"NUM", "def":"", "ro":"NO", "rq":"YES", "len":"24", "hid":"NO" }] }]}'  WHERE CFS_CODE='TCJPAR_IPAD' AND CFS_GROUP = '*';

-- For r5partctplconditions, insert keys into r5syscolumns
INSERT INTO [R5SYSCOLUMNS] ([TABLE_NAME], [COLUMN_NAME], [PRIMARY_KEY], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE], [IDENTITY_COLUMN], [ORDINAL_POSITION], [DMLTYPE]) VALUES ('R5PARTCTPLCONDITIONS', 'PTC_TEMPLATE', '+', null, null, null, null, null, null, 'N');
INSERT INTO [R5SYSCOLUMNS] ([TABLE_NAME], [COLUMN_NAME], [PRIMARY_KEY], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE], [IDENTITY_COLUMN], [ORDINAL_POSITION], [DMLTYPE]) VALUES ('R5PARTCTPLCONDITIONS', 'PTC_TEMPLATE_ORG', '+', null, null, null, null, null, null, 'N');
INSERT INTO [R5SYSCOLUMNS] ([TABLE_NAME], [COLUMN_NAME], [PRIMARY_KEY], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE], [IDENTITY_COLUMN], [ORDINAL_POSITION], [DMLTYPE]) VALUES ('R5PARTCTPLCONDITIONS', 'PTC_CONDITION', '+', null, null, null, null, null, null, 'N');


-- Book Labor screen config change for iPad
UPDATE r5configsettings  SET CFS_XMLCONFIG='{"sections":[{ "name":"Book Labor", "fields":[ {"id":"BOO_ACT", "lbl":"Activity", "type":"LOV-1", "def":"", "ro":"YES", "rq":"NO", "len":"20", "hid":"NO" }, {"id":"BOO_OCTYPE", "lbl":"Type of Hours", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_PERSON", "lbl":"Employee", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_MRC", "lbl":"Department", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_TRADE", "lbl":"Trade", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"200", "hid":"NO" }, {"id":"BOO_DATE", "lbl":"Start Date", "type":"DATE", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_STARTTIME", "lbl":"Start Time", "type":"COMBOBOX", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"NO" }, {"id":"BOO_ENDTIME", "lbl":"End Time", "type":"COMBOBOX", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"NO" }, {"id":"BOO_HOURS", "lbl":"Hours", "type":"COMBOBOX", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_CORRECTION", "lbl":"Correction", "type":"BOOL", "def":"", "ro":"NO", "rq":"NO", "len":"2", "hid":"NO" }] }]}' WHERE CFS_CODE='TCJBOO_IPAD' AND CFS_GROUP = '*';

-- Book Labor screen config change for iPhone
UPDATE r5configsettings  SET CFS_XMLCONFIG='{"sections":[{ "name":"", "fields":[ {"id":"BOO_ACT", "lbl":"Activity", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_OCTYPE", "lbl":"Type of Hours", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_PERSON", "lbl":"Employee", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_MRC", "lbl":"Department", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_TRADE", "lbl":"Trade", "type":"LOV-1", "def":"", "ro":"NO", "rq":"YES", "len":"200", "hid":"NO" }, {"id":"BOO_DATE", "lbl":"Start Date", "type":"DATE", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_STARTTIME", "lbl":"Start Time", "type":"COMBOBOX", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"YES" }, {"id":"BOO_ENDTIME", "lbl":"End Time", "type":"COMBOBOX", "def":"", "ro":"NO", "rq":"NO", "len":"20", "hid":"YES" }, {"id":"BOO_HOURS", "lbl":"Hours", "type":"COMBOBOX", "def":"", "ro":"NO", "rq":"YES", "len":"20", "hid":"NO" }, {"id":"BOO_CORRECTION", "lbl":"Correction", "type":"BOOL", "def":"", "ro":"NO", "rq":"NO", "len":"2", "hid":"YES" }] }]}', '2013-09-24 16:59:46' WHERE CFS_CODE='TCJBOO_IPHONE' AND CFS_GROUP = '*';




-- Equipment X, Y Coordinates
ALTER TABLE R5OBJECTS ADD COLUMN  OBJ_XCOORDINATE REAL;
ALTER TABLE R5OBJECTS ADD COLUMN  OBJ_YCOORDINATE REAL;

-- Clear r5gridfields
DELETE FROM R5GRIDFIELDS;

-- Part conditions
DROP TABLE R5PARTCTPLCONDITIONS;

CREATE TABLE R5PARTCTPLCONDITIONS ( 
    PTC_TEMPLATE              VARCHAR( 60 )      NOT NULL,
    PTC_TEMPLATE_ORG          VARCHAR( 30 )      NOT NULL,
    PTC_CONDITION             VARCHAR( 40 )      NOT NULL,
    PTC_DESC                  VARCHAR( 160 ),
    PTC_SUFFIXCODE            VARCHAR( 2 ),
    PTC_RETURNPROCE           NUMERIC( 6, 2 ),
    PTC_ISSUEPRIORITY         NUMERIC( 5, 2 ),
    PTC_RTNTOSTORECONDLIST    VARCHAR( 420 ),
    PTC_RTNTOSTORECONDDEFAULT VARCHAR( 40 ),
    PTC_RCVREPAIRCONDLIST     VARCHAR( 420 ),
    PTC_REPAIRCONDDEFAULT     VARCHAR( 40 ),
    PTC_ORDERABLE             VARCHAR( 2 ),
    PTC_PREVENTISSUE          VARCHAR( 2 ),
    PTC_CREATED               DATETIME( 8 ),
    PTC_CREATEDBY             VARCHAR( 60 ),
    PTC_UPDATED               DATETIME( 8 ),
    PTC_UPDATEDBY             VARCHAR( 60 ),
    PTC_UPDATEDCOUNT          NUMERIC( 17, 38 ) ,
  DMLTYPE NCHAR(1) NULL DEFAULT ('N')
);

-- Part conditions keys
INSERT INTO [R5SYSCOLUMNS] ([TABLE_NAME], [COLUMN_NAME], [PRIMARY_KEY], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE], [IDENTITY_COLUMN], [ORDINAL_POSITION], [DMLTYPE]) VALUES ('R5PARTCTPLCONDITIONS', 'PTC_TEMPLATE', '+', null, null, null, null, null, null, 'N');
INSERT INTO [R5SYSCOLUMNS] ([TABLE_NAME], [COLUMN_NAME], [PRIMARY_KEY], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE], [IDENTITY_COLUMN], [ORDINAL_POSITION], [DMLTYPE]) VALUES ('R5PARTCTPLCONDITIONS', 'PTC_TEMPLATE_ORG', '+', null, null, null, null, null, null, 'N');
INSERT INTO [R5SYSCOLUMNS] ([TABLE_NAME], [COLUMN_NAME], [PRIMARY_KEY], [DATA_TYPE], [CHARACTER_MAXIMUM_LENGTH], [NUMERIC_PRECISION], [NUMERIC_SCALE], [IDENTITY_COLUMN], [ORDINAL_POSITION], [DMLTYPE]) VALUES ('R5PARTCTPLCONDITIONS', 'PTC_CONDITION', '+', null, null, null, null, null, null, 'N');

DROP TABLE R5ACTCHECKLISTS;

CREATE TABLE R5ACTCHECKLISTS
(
    ACK_CODE NVARCHAR(30) NOT NULL,
    ACK_EVENT NVARCHAR(30) NOT NULL,
    ACK_ACT NUMERIC(8) NOT NULL,
    ACK_DESC NVARCHAR(80) NULL,
    ACK_SEQUENCE NUMERIC(8) NOT NULL,
    ACK_COMPLETED NVARCHAR(1) NULL,
    ACK_NOTES NVARCHAR(256) NULL,
    ACK_UPDATED DATETIME NULL,
    ACK_UPDATEDBY NVARCHAR(30) NULL,
    ACK_UPDATECOUNT NUMERIC(38) NULL,
    DMLTYPE NCHAR(1) NULL DEFAULT ('N'),
    ACK_LOTO nvarchar(30) NULL,
    ACK_OCCURRENCE numeric(8) NULL,
    ACK_POINT nvarchar(3) NULL,
    ACK_OBJECT nvarchar(30) NULL,
    ACK_OBJECT_ORG nvarchar(15) NULL,
    ACK_YES nvarchar(1) NULL,
    ACK_NO nvarchar(1) NULL,
    ACK_FINDING nvarchar(4) NULL,
    ACK_VALUE numeric(24,6) NULL,
    ACK_UOM nvarchar(30) NULL,
    ACK_FINALOCCURRENCE nvarchar(1) NULL,
    ACK_FOLLOWUP nvarchar(1) NULL,
    ACK_FOLLOWUPEVENT nvarchar(30) NULL,
    ACK_FOLLOWUPACT numeric(8) NULL,
    ACK_REQUIREDTOCLOSE nvarchar(8) NULL,
    ACK_SYSLEVEL nvarchar(30) NULL,
    ACK_ASMLEVEL nvarchar(30) NULL,
    ACK_COMPLEVEL nvarchar(30) NULL,
    ACK_COMPLOCATION nvarchar(80) NULL,
    ACK_CONDITION nvarchar(4) NULL,
    ACK_READING nvarchar(1) NULL,
    ACK_ASPECT nvarchar(4) NULL,
    ACK_POINTTYPE nvarchar(4) NULL,
    ACK_TASK nvarchar(20) NULL,
    ACK_MATLIST nvarchar(20) NULL,
    ACK_TYPE nvarchar(8) NULL,
    ACK_PARENTKEY nvarchar(30) NULL,
    ACK_POSSIBLEFINDINGS nvarchar(250) NULL,
    ACK_TASKCHECKLISTCODE nvarchar(30) NULL,
    ACK_OBJECTLEVEL nvarchar(8) NULL,
    PRIMARY KEY (ACK_CODE)
);

DROP TABLE R5ACTIVITIES;

CREATE TABLE R5ACTIVITIES
(
    ACT_EVENT NVARCHAR(30) NOT NULL,
    ACT_ACT NUMERIC(8) NOT NULL,
    ACT_PERRESP NVARCHAR(30),
    ACT_TRADE NVARCHAR(15),
    ACT_TASK NVARCHAR(20),
    ACT_START DATETIME,
    ACT_STARTTIME DATETIME,
    ACT_EST NUMERIC(24,6),
    ACT_PERSONS NUMERIC(8),
    ACT_MATLIST NVARCHAR(20),
    ACT_STATUS NCHAR(1),
    ACT_ALIAS NVARCHAR(45),
    ACT_MATLREV NUMERIC(4),
    ACT_TASKREV NUMERIC(4),
    ACT_USERTAG INTEGER DEFAULT (0),
    ACT_COMPLETED NCHAR(1),
    ACT_WARRANTY NVARCHAR(1),
    ACT_SYSLEVEL NVARCHAR(30),
    ACT_ASMLEVEL NVARCHAR(30),
    ACT_COMPLEVEL NVARCHAR(30),
    ACT_RPC NVARCHAR(4),
    ACT_WAP NVARCHAR(4),
    ACT_TPF NVARCHAR(4),
    ACT_MANUFACT NVARCHAR(24),
    ACT_NOTE NVARCHAR(80),
    ACT_DEFERMAINTENANCE NVARCHAR(1),
    ACT_HIRE NCHAR(1),
    ACT_QTY NUMERIC(10,2),
    ACT_DURATION NUMERIC(8),
    ACT_MRC NVARCHAR(15),
    ACT_UDFCHAR01 NVARCHAR(80),
    ACT_UDFCHAR02 NVARCHAR(80),
    ACT_UDFCHAR03 NVARCHAR(80),
    ACT_UDFCHAR04 NVARCHAR(80),
    ACT_UDFCHAR05 NVARCHAR(80),
    ACT_UDFCHAR06 NVARCHAR(80),
    ACT_UDFCHAR07 NVARCHAR(80),
    ACT_UDFCHAR08 NVARCHAR(80),
    ACT_UDFCHAR09 NVARCHAR(80),
    ACT_UDFCHAR10 NVARCHAR(80),
    ACT_UDFCHAR11 NVARCHAR(80),
    ACT_UDFCHAR12 NVARCHAR(80),
    ACT_UDFCHAR13 NVARCHAR(80),
    ACT_UDFCHAR14 NVARCHAR(80),
    ACT_UDFCHAR15 NVARCHAR(80),
    ACT_UDFCHAR16 NVARCHAR(80),
    ACT_UDFCHAR17 NVARCHAR(80),
    ACT_UDFCHAR18 NVARCHAR(80),
    ACT_UDFCHAR19 NVARCHAR(80),
    ACT_UDFCHAR20 NVARCHAR(80),
    ACT_UDFCHAR21 NVARCHAR(80),
    ACT_UDFCHAR22 NVARCHAR(80),
    ACT_UDFCHAR23 NVARCHAR(80),
    ACT_UDFCHAR24 NVARCHAR(80),
    ACT_UDFCHAR25 NVARCHAR(80),
    ACT_UDFCHAR26 NVARCHAR(80),
    ACT_UDFCHAR27 NVARCHAR(80),
    ACT_UDFCHAR28 NVARCHAR(80),
    ACT_UDFCHAR29 NVARCHAR(80),
    ACT_UDFCHAR30 NVARCHAR(80),
    ACT_UDFNUM01 NUMERIC(24,6),
    ACT_UDFNUM02 NUMERIC(24,6),
    ACT_UDFNUM03 NUMERIC(24,6),
    ACT_UDFNUM04 NUMERIC(24,6),
    ACT_UDFNUM05 NUMERIC(24,6),
    ACT_UDFDATE01 DATETIME,
    ACT_UDFDATE02 DATETIME,
    ACT_UDFDATE03 DATETIME,
    ACT_UDFDATE04 DATETIME,
    ACT_UDFDATE05 DATETIME,
    ACT_UDFCHKBOX01 NVARCHAR(1),
    ACT_UDFCHKBOX02 NVARCHAR(1),
    ACT_UDFCHKBOX03 NVARCHAR(1),
    ACT_UDFCHKBOX04 NVARCHAR(1),
    ACT_UDFCHKBOX05 NVARCHAR(1),
    ACT_PERFORMED DATETIME,
    ACT_PERFORMEDBY NVARCHAR(60),
    ACT_PERFORMEDTYPE NVARCHAR(8),
    ACT_REVIEWED DATETIME,
    ACT_REVIEWEDBY NVARCHAR(60),
    ACT_REVIEWEDTYPE NVARCHAR(8),
    DMLTYPE NCHAR(1),
    PRIMARY KEY (ACT_EVENT,ACT_ACT)
);

DROP TABLE R5ACTIVITYSTARTTIME;

CREATE TABLE R5ACTIVITYSTARTTIME
(
    BOO_EVENT NVARCHAR(30) NOT NULL,
    BOO_ACT NUMERIC(8) NOT NULL,
    BOO_START DATETIME NOT NULL
);

DROP TABLE R5ACTSCHEDULES;

CREATE TABLE R5ACTSCHEDULES
(
    ACS_EVENT NVARCHAR(30) NOT NULL,
    ACS_ACTIVITY NUMERIC(8) NOT NULL,
    ACS_RESPONSIBLE NVARCHAR(15),
    ACS_SCHED DATETIME,
    ACS_CODE NVARCHAR(30) NOT NULL,
    DMLTYPE nchar(1) DEFAULT ('N'),
    PRIMARY KEY (ACS_CODE)
);

DROP TABLE R5BOOKEDHOURS;

CREATE TABLE R5BOOKEDHOURS
(
    BOO_EVENT nvarchar(30) NOT NULL,
    BOO_ACT numeric(8) NOT NULL,
    BOO_ACD numeric(38) NOT NULL,
    BOO_DATE datetime,
    BOO_OCTYPE nvarchar(4),
    BOO_PERSON nvarchar(15),
    BOO_ON numeric(5),
    BOO_OFF numeric(5),
    BOO_HOURS numeric(24,6),
    BOO_MRC nvarchar(15),
    BOO_TRADE nvarchar(15),
    BOO_ALIAS nvarchar(45),
    BOO_CORRECTION nchar(1),
    BOO_COST numeric(24,6),
    BOO_RATE numeric(24,6),
    BOO_USERTAG integer DEFAULT (0),
    BOO_SPLITHOURS nvarchar(1),
    BOO_ORIGHOURS numeric(24,6),
    DMLTYPE nchar(1) DEFAULT ('N'),
    PRIMARY KEY (BOO_EVENT,BOO_ACT,BOO_ACD)
);

DROP TABLE R5PARTS;

CREATE TABLE R5PARTS
(
    PAR_CODE nvarchar(30) NOT NULL,
    PAR_DESC nvarchar(80),
    PAR_ORG nvarchar(15) NOT NULL,
    PAR_UOM nvarchar(30),
    PAR_BYASSET nchar(1),
    PAR_BYLOT nchar(1),
    PAR_NOTUSED nchar(1),
    PAR_REPAIRABLE nchar(1) DEFAULT ('-'),
    PAR_CALSTANDARD nchar(1),
    PAR_TRACKRTYPE nvarchar(16),
    DMLTYPE nchar(1) DEFAULT ('N'),
    PAR_TRACKBYCONDITION VARCHAR(2),
    PAR_PARENTPART VARCHAR(60),
    PAR_CONDITIONTPL VARCHAR(60),
    PAR_CONDITIONTPL_ORG VARCHAR(30),
    PAR_CONDITION VARCHAR(40),
    PRIMARY KEY (PAR_CODE,PAR_ORG)
);

DROP TABLE R5STANDWACTS;

CREATE TABLE R5STANDWACTS
(
    WAC_STANDWORK NVARCHAR(20) NOT NULL,
    WAC_ACT NUMERIC(8) NOT NULL,
    WAC_TRADE NVARCHAR(15),
    WAC_EST NUMERIC(12,2),
    WAC_TASK NVARCHAR(20),
    WAC_MATLIST NVARCHAR(20),
    WAC_PERSONS NUMERIC(8),
    WAC_START NUMERIC(3),
    WAC_DURATION NUMERIC(5) DEFAULT (1),
    DMLTYPE NCHAR(1) DEFAULT ('N'),
    PRIMARY KEY (WAC_STANDWORK,WAC_ACT)
);

DROP TABLE R5TASKCHECKLISTS;

CREATE TABLE R5TASKCHECKLISTS
(
    TCH_CODE NVARCHAR(30) NOT NULL,
    TCH_DESC NVARCHAR(80) NULL,
    TCH_SEQUENCE NUMERIC(5,4) NULL,
    TCH_NOTUSED NVARCHAR(1) NULL,
    TCH_TASK NVARCHAR(20) NULL,
    TCH_TASKREV NUMERIC(5,4) NULL,
    DMLTYPE NCHAR(1) NULL DEFAULT ('N'),
    TCH_TYPE nvarchar(8) NULL,
    TCH_REQUIREDTOCLOSE nvarchar(8) NULL,
    TCH_OBJECTLEVEL nvarchar(8) NULL,
    TCH_OBJECTCLASS nvarchar(8) NULL,
    TCH_OBJECTCLASS_ORG nvarchar(15) NULL,
    TCH_OBJECTCATEGORY nvarchar(30) NULL,
    TCH_UOM nvarchar(30) NULL,
    TCH_ASPECT nvarchar(4) NULL,
    TCH_POINTTYPE nvarchar(4) NULL,
    TCH_REPEATING nvarchar(1) NULL,
    TCH_FOLLOWUPTASK nvarchar(20) NULL,
    TCH_MATLIST nvarchar(20) NULL,
    TCH_SYSLEVEL nvarchar(30) NULL,
    TCH_ASMLEVEL nvarchar(30) NULL,
    TCH_COMPLEVEL nvarchar(30) NULL,
    TCH_COMPLOCATION nvarchar(80) NULL,
    TCH_CONDITION nvarchar(4) NULL,
    TCH_POSSIBLEFINDINGS nvarchar(250) NULL,
    PRIMARY KEY (TCH_CODE)
);

DROP TABLE R5TASKS;

CREATE TABLE R5TASKS
(
    TSK_CODE NVARCHAR(20) NOT NULL,
    TSK_DESC NVARCHAR(80),
    TSK_REVISION NUMERIC(4) NOT NULL,
    TSK_ORG NVARCHAR(15),
    TSK_PERSONS NUMERIC(8),
    TSK_TRADE NVARCHAR(15),
    TSK_REVRSTATUS NVARCHAR(4),
    TSK_SYSLEVEL NVARCHAR(30),
    TSK_ASMLEVEL NVARCHAR(30),
    TSK_COMPLEVEL NVARCHAR(30),
    TSK_RPC NVARCHAR(4),
    TSK_WAP NVARCHAR(4),
    TSK_TPF NVARCHAR(4),
    TSK_MANUFACT NVARCHAR(24),
    TSK_HOURS NUMERIC(14,4),
    TSK_UOM NVARCHAR(30),
    TSK_NOTUSED NVARCHAR(1),
    DMLTYPE NCHAR(1) DEFAULT ('N'),
    TSK_ACTIVECHECKLIST VARCHAR(1),
    TSK_ISOLATIONMETHOD nvarchar(1) NULL,
    TSK_CHECKLISTPERFBYREQ nvarchar(1) NULL,
    TSK_CHECKLISTREVBYREQ nvarchar(1) NULL,
    TSK_WOTYPE nvarchar(8) NULL,
    TSK_WOCLASS nvarchar(8) NULL,
    TSK_WOCLASS_ORG nvarchar(15) NULL,
    TSK_WOSTATUS nvarchar(4) NULL,
    TSK_WOPRIORITY nvarchar(8) NULL,
    TSK_WODESC nvarchar(80) NULL,
    PRIMARY KEY (TSK_CODE,TSK_REVISION)
);

DROP TABLE R5TRANSACTIONS;

CREATE TABLE R5TRANSACTIONS
(
    TRA_CODE nvarchar(30) NOT NULL,
    TRA_DESC nvarchar(80) NOT NULL,
    TRA_TYPE nvarchar(4) NOT NULL,
    TRA_RTYPE nvarchar(4) NOT NULL,
    TRA_DATE datetime NOT NULL,
    TRA_STATUS nvarchar(4) NOT NULL,
    TRA_RSTATUS nvarchar(4) NOT NULL,
    TRA_FROMENTITY nvarchar(4),
    TRA_FROMRENTITY nvarchar(4),
    TRA_FROMTYPE nvarchar(4),
    TRA_FROMRTYPE nvarchar(4),
    TRA_FROMCODE nvarchar(30),
    TRA_FROMCODE_ORG nvarchar(15),
    TRA_ORG nvarchar(15) NOT NULL,
    TRA_TOENTITY nvarchar(4),
    TRA_TORENTITY nvarchar(4),
    TRA_TOTYPE nvarchar(4),
    TRA_TORTYPE nvarchar(4),
    TRA_TOCODE nvarchar(30),
    TRA_TOCODE_ORG nvarchar(15),
    TRA_PERS nvarchar(15),
    TRA_IR nvarchar(6),
    TRA_EVENT nvarchar(30),
    TRA_ACT numeric(8),
    TRA_OBJECT nvarchar(30),
    TRA_OBJECT_ORG nvarchar(15),
    TRA_PROJECT nvarchar(20),
    TRA_PROJBUD nvarchar(20),
    TRA_MRC nvarchar(15),
    TRA_COSTCODE nvarchar(30),
    TRA_STORE nvarchar(15),
    TRA_MATLIST nvarchar(20),
    TRA_MATLREV numeric(4),
    TRA_USERTAG integer DEFAULT (0),
    TRA_ROUTEPARENT nvarchar(30),
    TRA_SPLITTRANS nvarchar(1),
    DMLTYPE nchar(1) DEFAULT ('N'),
    PRIMARY KEY (TRA_CODE)
);

DROP TABLE R5TRANSLINES;

CREATE TABLE R5TRANSLINES
(
    TRL_TRANS nvarchar(30) NOT NULL,
    TRL_TYPE nvarchar(4),
    TRL_RTYPE nvarchar(4),
    TRL_LINE numeric(8) NOT NULL,
    TRL_DATE datetime,
    TRL_EVENT nvarchar(30),
    TRL_ACT numeric(8),
    TRL_PART nvarchar(30),
    TRL_PART_ORG nvarchar(15),
    TRL_OBJECT nvarchar(30),
    TRL_OBJECT_ORG nvarchar(15),
    TRL_STORE nvarchar(15),
    TRL_BIN nvarchar(15),
    TRL_LOT nvarchar(12),
    TRL_QTY numeric(24,6),
    TRL_AVAILQTY numeric(24,6),
    TRL_BYASSET nchar(1),
    TRL_REPAIRABLE nchar(1),
    TRL_USERTAG integer DEFAULT (0),
    TRL_SPLITTRANS nvarchar(1),
    TRL_ORIGQTY numeric(24,6),
    TRL_MANUFACTURER nvarchar(24),
    TRL_MANUFACTPART nvarchar(50),
    DMLTYPE nchar(1) DEFAULT ('N'),
    TRL_ISSUEDPART VARCHAR(30),
    TRL_CONDITION VARCHAR(20),
    TRL_RETURNCONDITION VARCHAR(20),
    PRIMARY KEY (TRL_TRANS,TRL_LINE)
);


UPDATE R5LISTENTITY
SET LET_UPDATED = NULL
WHERE LET_TABLENAME IN ('R5OBJECTS','R5PARTCTPLCONDITIONS','R5ACTCHECKLISTS','R5ACTIVITIES','R5ACTSCHEDULES','R5BOOKEDHOURS','R5PARTS','R5STANDWACTS','R5TASKCHECKLISTS','R5TASKS','R5TRANSACTIONS','R5TRANSLINES');

UPDATE R5LISTENTITY
SET LET_CONNECTEDMODE = '+', LET_UPDATED = NULL
WHERE LET_TABLENAME IN ('R5FINDINGS','R5FINCLASSES');

INSERT INTO [R5LISTENTITY] ([LET_DATAGRID], [LET_SEQNO], [LET_MASK], [LET_DOWNCAT], [LET_GROUPID], [LET_BLOCKSIZE], [LET_DELINSUPD], [LET_FILTER], [LET_TABLENAME], [LET_ORGKEY], [LET_DOWNGROUP], [LET_FILTERPARAMS], [LET_CONNECTEDMODE], [LET_ALWAYSDOWNLOAD], [LET_UPDATED], [LET_MASTERTABLE], [ROWIDENTITY]) VALUES ('SCPARTCON', 918, null, null, null, null, 3, 'SCPART', 'R5PARTCTPLCONDITIONS', 'PTC_TEMPLATE_ORG', null, null, '-', '-', null, null, null);

UPDATE R5LISTENTITY SET LET_CONNECTEDMODE = '+' WHERE LET_DATAGRID = 'BCORGS';