
/*==============================================================*/
/* Table: AddObjectData                                         */
/*==============================================================*/
create table AddObjectData (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   AddObjectDataType    int                  not null,
   TIdd                 int                  null,
   AOD_Int              int                  null,
   AOD_Char             nvarchar(500)         null,
   AOD_Idd              int                  not null,
   AOD_Time             datetime             null,
   Change               datetime             null,
   Status               int                  null,
   constraint PK_ADDOBJECTDATA primary key  (AOD_Idd)
   )
go

/*==============================================================*/
/* Index: I00081                                                */
/*==============================================================*/
create index I00081 on AddObjectData (
AddObjectDataType ASC
)
go

/*==============================================================*/
/* Table: AnwserGroup                                           */
/*==============================================================*/
create table AnwserGroup (
   GroupID              int                  not null,
   QuestionType         int                  null,
   GroupName            nvarchar(50)          null,
   constraint PK_ANWSERGROUP primary key (GroupID)
)
go

/*==============================================================*/
/* Table: Anwsers                                               */
/*==============================================================*/
create table Anwsers (
   AnwserID             int                  not null,
   GroupID              int                  null,
   Anwser               nvarchar(50)          null,
   OrderNr              int                  null,
   constraint PK_ANWSERS primary key (AnwserID)
)
go

/*==============================================================*/
/* Table: BData                                                 */
/*==============================================================*/
create table BData (
   BinaryData           image       null,
   BDataIdx             int                  not null,
   Code                 nvarchar(50)          null,
   Firm                 int                  null,
   Type                 int                  null,
   Sub_Code             nvarchar(50)          null,
   Sub_Firm             int                  null,
   Sub_Type             int                  null,
   SIdd                 int                  null,
   Head                 nvarchar(50)          null,
   Hea_Firm             int                  null,
   DocType              int                  null,
   constraint PK_BDATA primary key (BDataIdx)
)
go

/*==============================================================*/
/* Table: Barcode                                               */
/*==============================================================*/
create table Barcode (
   BIdd                 int                  not null,
   Firm                 int                  null,
   Code                 nvarchar(50)          null,
   Type                 int                  not null,
   BarCode              nvarchar(50)          not null,
   Status               int                  not null,
   SIdd                 int                  null,
   BcType               int                  null,
   CustomerCode         nvarchar(50)          null,
   constraint PK_BARCODE primary key (BIdd)
)
go

/*==============================================================*/
/* Index: I00005                                                */
/*==============================================================*/
create index I00005 on Barcode (
SIdd ASC
)
go

/*==============================================================*/
/* Index: I00006                                                */
/*==============================================================*/
create index I00006 on Barcode (
Firm ASC,
Code ASC,
Type ASC
)
go

/*==============================================================*/
/* Index: I00007                                                */
/*==============================================================*/
create index I00007 on Barcode (
BarCode ASC
)
go

/*==============================================================*/
/* Index: I00011                                                */
/*==============================================================*/
create index I00011 on Barcode (
CustomerCode ASC
)
go

/*==============================================================*/
/* Table: Classes                                               */
/*==============================================================*/
create table Classes (
   ClassIdx             int                  not null,
   Firm                 int                  null,
   Type                 int                  null,
   ClassCode            nvarchar(50)          null,
   Name                 nvarchar(50)          null,
   Description          nvarchar(50)          null,
   Status               int                  null,
   constraint PK_CLASSES primary key (ClassIdx)
)
go

/*==============================================================*/
/* Table: Customer                                              */
/*==============================================================*/
create table Customer (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   Change               datetime             null,
   Name_full            nvarchar(250)         null,
   Address              nvarchar(50)          null,
   City                 nvarchar(50)          null,
   Country              nvarchar(50)          null,
   TaxNumber            nvarchar(50)          null,
   LinkToUpper          nvarchar(50)          null,
   Categ1               nvarchar(50)          null,
   Categ2               nvarchar(50)          null,
   Categ3               nvarchar(50)          null,
   AddParam1            nvarchar(50)          null,
   AddParam2            nvarchar(50)          null,
   AddParam3            nvarchar(50)          null,
   Status               int                  not null,
   Discount             float                null,
   DueDuration          int                  null,
   PriceList            int                  null,
   Block                smallint             null,
   Buyer                smallint             null,
   Supplier             smallint             null,
   Warehouse            smallint             null,
   LimitAmount          float                null,
   CurrentDebt          float                null,
   DefaultPaymentMethod int                  null,
   Owner                int                  null,
   LinkToUpperType      int                  null,
   proContract1         nvarchar(15)          null,
   proContract2         nvarchar(15)          null,
   proPriceList         nvarchar(5)           null,
   proCustType          nvarchar(15)          null,
   CommonInvoice        int                  null,
   sapContCred         nvarchar(15)          null,
   sapSortInvoice      nvarchar(3)           null,
   sapSortDelNote      nvarchar(3)           null,
   sapSortPricesDelNote nvarchar(3)           null,
   sapPackingPayable    nchar(1)              null,
   sapOldestOpenClaim   datetime             null,
   CustomField1 		nvarchar(250) 		 null,
   CustomField2 		nvarchar(250) 		 null,
   CustomField3 		nvarchar(250) 		 null,
   CustomField4 		nvarchar(250) 		 null,
   CustomField5 		nvarchar(250) 		 null,
   constraint PK_CUSTOMER primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: DL_SetSubjPriceCateg                                  */
/*==============================================================*/
create table DL_SetSubjPriceCateg (
   Firm                 int                  not null,
   acSubject            nvarchar(30)          not null,
   acClassif            nvarchar(16)          not null,
   acInvoInOut          nchar(1)              not null,
   adDateStart          datetime             not null,
   adDateEnd            datetime             null,
   acType               nchar(1)              null,
   anPrice              float                null,
   anRebate             float                null,
   anRebate2            float                null,
   anRebate3            float                null,
   acCurrency           nchar(3)              null,
   acFormula            nchar(3)              null,
   anDeliveryDeadline   int                  null,
   anPaymentDeadline    int                  null,
   constraint PK_DL_SETSUBJPRICECATEG primary key (Firm, acSubject, acClassif, acInvoInOut, adDateStart)
)
go

/*==============================================================*/
/* Table: DL_SetSubjPriceItem                                   */
/*==============================================================*/
create table DL_SetSubjPriceItem (
   Firm                 int                  not null,
   acSubject            nvarchar(30)          not null,
   acIdent              nvarchar(16)          not null,
   acInvoInOut          nchar(1)              not null,
   adDateStart          datetime             not null,
   adDateEnd            datetime             null,
   acType               nchar(1)              null,
   anPrice              float                null,
   anRebate             float                null,
   anRebate2            float                null,
   anRebate3            float                null,
   acCurrency           nchar(3)              null,
   acFormula            nchar(3)              null,
   anDeliveryDeadline   int                  null,
   anPaymentDeadline    int                  null,
   constraint PK_DL_SETSUBJPRICEITEM primary key (Firm, acSubject, acIdent, acInvoInOut, adDateStart)
)
go

/*==============================================================*/
/* Table: DL_SetSubjTypePriceCateg                              */
/*==============================================================*/
create table DL_SetSubjTypePriceCateg (
   Firm                 int                  not null,
   acSubjType           nvarchar(16)          not null,
   acClassif            nvarchar(16)          not null,
   acInvoInOut          nchar(1)              not null,
   adDateStart          datetime             not null,
   adDateEnd            datetime             null,
   acType               nchar(1)              null,
   anPrice              float                null,
   anRebate             float                null,
   anRebate2            float                null,
   anRebate3            float                null,
   acCurrency           nchar(3)              null,
   acFormula            nchar(3)              null,
   anDeliveryDeadline   int                  null,
   anPaymentDeadline    int                  null,
   constraint PK_DL_SETSUBJTYPEPRICECATEG primary key (Firm, acSubjType, acClassif, acInvoInOut, adDateStart)
)
go

/*==============================================================*/
/* Table: DL_SetSubjTypePriceItem                               */
/*==============================================================*/
create table DL_SetSubjTypePriceItem (
   Firm                 int                  not null,
   acSubjType           nvarchar(16)          not null,
   acIdent              nvarchar(16)          not null,
   acInvoInOut          nchar(1)              not null,
   adDateStart          datetime             not null,
   adDateEnd            datetime             null,
   acType               nchar(1)              null,
   anPrice              float                null,
   anRebate             float                null,
   anRebate2            float                null,
   anRebate3            float                null,
   acCurrency           nchar(3)              null,
   acFormula            nchar(3)              null,
   anDeliveryDeadline   int                  null,
   anPaymentDeadline    int                  null,
   constraint PK_DL_SETSUBJTYPEPRICEITEM primary key (Firm, acSubjType, acIdent, acInvoInOut, adDateStart)
)
go

/*==============================================================*/
/* Table: DelNote                                               */
/*==============================================================*/
create table DelNote (
   Firm                 int                  not null,
   DocType              int                  not null,
   Head                 nvarchar(50)          not null,
   DelNote              nvarchar(50)          not null,
   TIdd                 int                  null,
   UserIdx              int                  null,
   DelNoteLink          nvarchar(50)          null,
   txt                  int                  null,
   DTLastChange         datetime             null,
   DTCreation           datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Status               int                  null,
   BagSerial            nvarchar(30)          null,
   BagMark1             nvarchar(30)          null,
   BagMark2             nvarchar(30)          null,
   constraint PK_DELNOTE primary key (DelNote, Head, Firm, DocType)
)
go

/*==============================================================*/
/* Index: I10001                                                */
/*==============================================================*/
create index I10001 on DelNote (
Firm ASC,
DocType ASC,
Head ASC,
DelNote ASC,
Status ASC
)
go

/*==============================================================*/
/* Index: I20001                                                */
/*==============================================================*/
create index I20001 on DelNote (
BagMark1 ASC,
BagMark2 ASC
)
go

/*==============================================================*/
/* Table: DocLocalHistoryViewAtl                                */
/*==============================================================*/
create table DocLocalHistoryViewAtl (
   CompanyCode          nvarchar(50)          not null,
   ProductCode          nvarchar(50)          not null,
   Order1               float                null,
   Order2               float                null,
   Order3               float                null,
   Order4               float                null,
   Order5               float                null,
   constraint PK_DOCLOCALHISTORYVIEWATL primary key (CompanyCode, ProductCode)
)
go

/*==============================================================*/
/* Table: DocSettings                                           */
/*==============================================================*/
create table DocSettings (
   DT2_Idd              int                  not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   IValue               int                  null,
   CValue               nvarchar(50)          null,
   Fvalue               float                null,
   constraint PK_DOCSETTINGS primary key (DT2_Idd, Firm, Type)
)
go

/*==============================================================*/
/* Table: Documents_Stock_link                                  */
/*==============================================================*/
create table Documents_Stock_link (
   Firm                 int                  null,
   Hea_DocType          int                  null,
   Del_DocType          int                  null,
   Pos_DocType          int                  null,
   DocType              int                  null,
   DIdd                 int                  not null,
   SIdd                 int                  null,
   Head                 nvarchar(50)          null,
   DelNote              nvarchar(50)          null,
   Position             int                  null,
   OutSerial            int                  null,
   Change               datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Status               int                  null,
   constraint PK_DOCUMENTS_STOCK_LINK primary key (DIdd)
)
go

/*==============================================================*/
/* Index: I00013                                                */
/*==============================================================*/
create index I00013 on Documents_Stock_link (
Firm ASC,
Head ASC,
DelNote ASC,
Position ASC,
OutSerial ASC
)
go

/*==============================================================*/
/* Index: DSL_Stock_Sidd                                        */
/*==============================================================*/
create index DSL_Stock_Sidd on Documents_Stock_link (
SIdd ASC
)
go

/*==============================================================*/
/* Table: ErpHeads                                              */
/*==============================================================*/
create table ErpHeads (
   PartD                nvarchar(15)          null,
   PartC                nvarchar(15)          null,
   PartB                nvarchar(15)          null,
   PartA                nvarchar(15)          null,
   EHIdd                int                  not null,
   TIdd                 int                  null,
   Firm                 int                  null,
   ErpDocIdd            nvarchar(50)          null,
   Status               int                  null,
   Add1                 nvarchar(50)          null,
   Add2                 nvarchar(50)          null,
   constraint PK_ERPHEADS primary key (EHIdd)
)
go

/*==============================================================*/
/* Table: FilterHead                                            */
/*==============================================================*/
create table FilterHead (
   Type                 int                  not null,
   FilterName           nvarchar(50)         not null,
   Id                   int                  not null,
   Description          nvarchar(150)        null,
   AddParam1            nvarchar(50)         null,
   InsertDate           datetime             null,
   ChangeDate           datetime             null,
   constraint PK_FILTERHEAD primary key (Type, Id)
)
go

/*==============================================================*/
/* Table: FilterPosition                                        */
/*==============================================================*/
create table FilterPosition (
   Type                 int                  not null,
   Id                   int                  not null,
   Position             int                  not null,
   Firm                 int                  null,
   Code                 nvarchar(50)         null,
   constraint PK_FILTERPOSITION primary key (Type, Id, Position)
)
go

/*==============================================================*/
/* Table: Firm                                                  */
/*==============================================================*/
create table Firm (
   Firm                 int                  not null,
   Name                 nvarchar(50)          null,
   Description          nvarchar(50)          null,
   Status               int                  null,
   Type               int                  null,
   constraint PK_FIRM primary key (Firm)
)
go

/*==============================================================*/
/* Table: Head                                                  */
/*==============================================================*/
create table Head (
   Firm                 int                  not null,
   Head                 nvarchar(50)         not null,
   DocType              int                  not null,
   Code                 nvarchar(50)         null,
   Type                 int                  null,
   TIdd                 int                  null,
   UserIdx              int                  null,
   PaymentMethod        int                  null,
   HeadLink             nvarchar(50)         null,
   HeadLinkMobos    nvarchar(50)         null,
   txt                  int                  null,
   DTLastChange         datetime             null,
   DTLastPrint          datetime             null,
   DTCreation           datetime             null,
   DTAdv                datetime             null,
   DTAdd1               datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   AddParam1            nvarchar(50)         null,
   AddParam2            nvarchar(50)         null,
   AddParam3            nvarchar(50)         null,
   Status               int                  null,
   SuperDiscount        float                null,
   AddParam4            nvarchar(50)         null,
   SourceWarehouseCode  nvarchar(50)         null,
   SourceWarehouseType  int                  null,
   DestinationWarehouseCode nvarchar(50)     null,
   DestinationWarehouseType int              null,
   Notes                nvarchar(250)        null,
   PrintedDocType       int                  null,
   reference            nvarchar(20)         null,
   Amount1		float	             null,
   Amount2		float		     null,
   PriorityOrder        int                  null,
   ERPStatus            int                  null,
   ERPExport            int                  null,
   constraint PK_HEAD primary key  (Head, Firm, DocType)
)
go

/*==============================================================*/
/* Index: I00017                                                */
/*==============================================================*/
create index I00017 on Head (
Code ASC,
Firm ASC,
Type ASC
)
go

/*==============================================================*/
/* Index: I00018                                                */
/*==============================================================*/
create index I00018 on Head (
Firm ASC,
Head ASC,
DocType ASC,
Status ASC
)
go

/*==============================================================*/
/* Table: HeadLinkErpHeads                                      */
/*==============================================================*/
create table HeadLinkErpHeads (
   EHIdd                int                  not null,
   Head                 nvarchar(50)          not null,
   Firm                 int                  not null,
   DocType              int                  not null,
   TIdd                 int                  null,
   Add1                 nvarchar(50)          null,
   Add2                 nvarchar(50)          null,
   Status               int                  null,
   LinkIdd              int                  not null,
   constraint PK_HEADLINKERPHEADS primary key (EHIdd, Head, Firm, DocType, LinkIdd)
)
go

/*==============================================================*/
/* Index: I00086                                                */
/*==============================================================*/
create index I00086 on HeadLinkErpHeads (
Head ASC,
Firm ASC,
DocType ASC
)
go

/*==============================================================*/
/* Table: Inventory                                             */
/*==============================================================*/
create table Inventory (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   BDataIdx             int                  null,
   TL_Idd               int                  null,
   Change               datetime             null,
   Status               int                  not null,
   Name_full            nvarchar(250)         null,
   by_pcs               int                  null,
   bad_sticker          int                  null,
   for_remove           int                  null,
   AddParam1            nvarchar(50)          null,
   AddParam2            nvarchar(50)          null,
   Last                 datetime             null,
   Next                 datetime             null,
   New                  int                  null,
   CustomField1 		nvarchar(250) 		 null,
   CustomField2 		nvarchar(250) 		 null,
   CustomField3 		nvarchar(250) 		 null,
   CustomField4 		nvarchar(250) 		 null,
   CustomField5 		nvarchar(250) 		 null,
   constraint PK_INVENTORY primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Index: I00106                                                */
/*==============================================================*/
create index I00106 on Inventory (
Code ASC,
Firm ASC,
Type ASC
)
go

/*==============================================================*/
/* Table: Locations                                             */
/*==============================================================*/
create table Locations (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   LocCode              nvarchar(50)         null,
   LocFirm              int                  null,
   LocType              int                  null,
   Change               datetime             null,
   Name_full            nvarchar(250)         null,
   Status               int                  not null,
   AddInt1              int                  null,
   AddInt2              int                  null,
   AddChar1             nvarchar(50)          null,
   AddChar2             nvarchar(50)          null,
   Weight               int                  null,
   CustomField1 		nvarchar(250) 		 null,
   CustomField2 		nvarchar(250) 		 null,
   CustomField3 		nvarchar(250) 		 null,
   CustomField4 		nvarchar(250) 		 null,
   CustomField5 		nvarchar(250) 		 null,
   New					int					 null,
   LeftExtent			int					 null,
   RightExtent			int					 null,
   constraint PK_LOCATIONS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Index: I00087                                                */
/*==============================================================*/
create unique index I00087 on Locations (
LocCode ASC,
LocFirm ASC,
LocType ASC,
Code ASC,
Firm ASC,
Type ASC
)
go

/*==============================================================*/
/* Table: Menu                                                  */
/*==============================================================*/
create table Menu (
   MenuIdx              int                  not null,
   MenuGroupIdx         int                  not null,
   TitleMenu            nvarchar(50)          not null,
   constraint PK_MENU primary key  (MenuIdx, MenuGroupIdx)
)
go

/*==============================================================*/
/* Index: I00022                                                */
/*==============================================================*/
create index I00022 on Menu (
MenuGroupIdx ASC
)
go

/*==============================================================*/
/* Table: MenuGroup                                             */
/*==============================================================*/
create table MenuGroup (
   MenuGroupIdx         int                  not null,
   TitleGroup           nvarchar(50)          null,
   constraint PK_MENUGROUP primary key  (MenuGroupIdx)
)
go

/*==============================================================*/
/* Table: MicroFilm                                             */
/*==============================================================*/
create table MicroFilm (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   change               datetime             null,
   AddParam1            nvarchar(50)          null,
   AddParam2            nvarchar(50)          null,
   AddParam3            nvarchar(50)          null,
   AddParam4            nvarchar(50)          null,
   SteviloPosnetkov     int                  null,
   DatumSnemanja        datetime             null,
   SteviloDK            int                  null,
   DatumArhiviranja     datetime             null,
   DatumOddaje          datetime             null,
   AddParam5            int                  null,
   AddParam6            int                  null,
   Status               int                  not null,
   "Insert"             datetime             null,
   constraint PK_MICROFILM primary key  (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: OPersons                                              */
/*==============================================================*/
create table OPersons (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   FName                nvarchar(50)          null,
   MName                nvarchar(50)          null,
   SName                nvarchar(50)          null,
   EMSO                 nvarchar(13)          null,
   OSS                  nvarchar(10)          null,
   OE                   nvarchar(50)          null,
   Status               int                  not null,
   InsertDateTime       datetime             null,
   ChangeDateTime       datetime             null,
   PrintDateTime        datetime             null,
   constraint PK_OPERSONS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: OSearch                                               */
/*==============================================================*/
create table OSearch (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   IntStart             int                  null,
   IntEnd               int                  null,
   StringStart          nvarchar(50)          null,
   StringEnd            nvarchar(50)          null,
   TimeStart            datetime             null,
   TimeEnd              datetime             null,
   Idd                  int                  not null,
   DataSearchType       int                  not null,
   AddParam1            nvarchar(50)          null,
   AddParam2            int                  null,
   Status               int                  null,
   constraint PK_OSEARCH primary key  (Idd)
)
go

/*==============================================================*/
/* Index: I00089                                                */
/*==============================================================*/
create index I00089 on OSearch (
IntStart ASC,
DataSearchType ASC,
AddParam1 ASC,
AddParam2 ASC
)
go

/*==============================================================*/
/* Index: I00090                                                */
/*==============================================================*/
create index I00090 on OSearch (
IntEnd ASC,
DataSearchType ASC,
AddParam1 ASC,
AddParam2 ASC
)
go

/*==============================================================*/
/* Index: I00091                                                */
/*==============================================================*/
create index I00091 on OSearch (
StringStart ASC,
DataSearchType ASC,
AddParam1 ASC,
AddParam2 ASC
)
go

/*==============================================================*/
/* Index: I00092                                                */
/*==============================================================*/
create index I00092 on OSearch (
StringEnd ASC,
DataSearchType ASC,
AddParam1 ASC,
AddParam2 ASC
)
go

/*==============================================================*/
/* Index: I00093                                                */
/*==============================================================*/
create index I00093 on OSearch (
TimeStart ASC,
DataSearchType ASC,
AddParam1 ASC,
AddParam2 ASC
)
go

/*==============================================================*/
/* Index: I00094                                                */
/*==============================================================*/
create index I00094 on OSearch (
TimeEnd ASC,
DataSearchType ASC,
AddParam1 ASC,
AddParam2 ASC
)
go

/*==============================================================*/
/* Table: Object                                                */
/*==============================================================*/
create table Object (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Change               datetime             null,
   Type                 int                  not null,
   TIdd                 int                  null,
   TL_Idd               int                  null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Name                 nvarchar(50)          null,
   Name_ASCII           nvarchar(50)          null,
   Status               int                  not null,
   constraint PK_OBJECT primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Index: I00025                                                */
/*==============================================================*/
create index I00025 on Object (
Name ASC
)
go

/*==============================================================*/
/* Index: I00026                                                */
/*==============================================================*/
create index I00026 on Object (
Status ASC
)
go

/*==============================================================*/
/* Table: ObjectLists                                           */
/*==============================================================*/
create table ObjectLists (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   TL_Idd               int                  null,
   change               datetime             null,
   Name_full            nvarchar(250)         null,
   Status               int                  not null,
   constraint PK_OBJECTLISTS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: Object_Interconnections                               */
/*==============================================================*/
create table Object_Interconnections (
   DateTime1            datetime             null,
   DateTime2            datetime             null,
   OIC_Idd              int                  not null,
   Code                 nvarchar(50)          null,
   Firm                 int                  null,
   Type                 int                  null,
   Prev_Code            nvarchar(50)          null,
   Prev_Firm            int                  null,
   Prev_Type            int                  null,
   Curr_Code            nvarchar(50)          null,
   Curr_Firm            int                  null,
   Curr_Type            int                  null,
   Priority             int                  null,
   Status               int                  not null,
   PackAmount           float                null,
   constraint PK_OBJECT_INTERCONNECTIONS primary key (OIC_Idd)
)
go

/*==============================================================*/
/* Index: I00027                                                */
/*==============================================================*/
create index I00027 on Object_Interconnections (
Code ASC,
Firm ASC,
Type ASC
)
go

/*==============================================================*/
/* Index: I00028                                                */
/*==============================================================*/
create index I00028 on Object_Interconnections (
Prev_Code ASC,
Prev_Firm ASC,
Prev_Type ASC
)
go

/*==============================================================*/
/* Index: I00029                                                */
/*==============================================================*/
create index I00029 on Object_Interconnections (
Curr_Code ASC,
Curr_Firm ASC,
Curr_Type ASC
)
go

/*==============================================================*/
/* Table: Object_Locations_Interconnections                     */
/*==============================================================*/

CREATE TABLE Object_Locations_Interconnections(
	ObjectCode 			nvarchar(50) 			NOT NULL,
	ObjectFirm 			int 					NOT NULL,
	ObjectType 			int 					NOT NULL,
	LocCode 			nvarchar(50) 			NOT NULL,
	LocFirm 			int 					NOT NULL,
	LocType 			int 					NOT NULL,
 CONSTRAINT PK_OBJECT_LOCATIONS PRIMARY KEY (ObjectCode,ObjectFirm,ObjectType,LocCode,LocFirm,LocType)
)
go

/*==============================================================*/
/* Table: OrderDelegation                                       */
/*==============================================================*/

create table OrderDelegation (
   Head                nvarchar(50)          not null,
   Firm                 int                  not null,
   DocType              int                  not null,
   TerminalIdx          int                  not null,
   DTCreation           datetime             null,
   DTLastChange         datetime             null,
   Status               int                  null,
   constraint PK_ORDERDELEGATION primary key (Head, Firm, DocType, TerminalIdx)
)
go

/*==============================================================*/
/* Table: OutSerial                                             */
/*==============================================================*/
create table OutSerial (
   Firm                 int                  not null,
   DocType              int                  not null,
   Head                 nvarchar(50)          not null,
   DelNote              nvarchar(50)          not null,
   Position             int                  not null,
   OutSerial            int                  not null,
   TIdd                 int                  null,
   UserIdx              int                  null,
   OutSerialLink        int                  null,
   txt                  int                  null,
   DTCreation           datetime             null,
   DTLastChange         datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Serial               nvarchar(50)          null,
   SerialLink           int                  null,
   Status               int                  null,
   constraint PK_OUTSERIAL primary key (OutSerial, Head, DelNote, Position, Firm, DocType)
)
go

/*==============================================================*/
/* Table: Overrides                                             */
/*==============================================================*/
create table Overrides (
   OverridesIdd         int                  not null,
   BIdd                 int                  null,
   Firm                 int                  null,
   Type                 int                  null,
   Object_Code          nvarchar(50)         null,
   Subject_Code         nvarchar(50)         null,
   Change               datetime             null,
   Status               int                  null,
   PriceMin				float				 NULL,
   PriceMax			float				 NULL,
   constraint PK_OVERRIDES primary key  (OverridesIdd)
)
go

/*==============================================================*/
/* Index: I00095                                                */
/*==============================================================*/
create index I00095 on Overrides (
Firm ASC,
Type ASC,
Object_Code ASC
)
go

/*==============================================================*/
/* Index: I00096                                                */
/*==============================================================*/
create index I00096 on Overrides (
Firm ASC,
Type ASC,
Subject_Code ASC
)
go

/*==============================================================*/
/* Table: OverridesAddInfo                                      */
/*==============================================================*/
create table OverridesAddInfo (
   OverridesAddInfo     int                  not null,
   OverridesIdd         int                  null,
   Firm                 int                  null,
   Type                 int                  null,
   AddInt1              float                null,
   AddInt2              int                  null,
   AddChar1             nvarchar(50)          null,
   AddChar2             nvarchar(50)          null,
   Status               int                  null,
   constraint PK_OVERRIDESADDINFO primary key (OverridesAddInfo)
)
go

/*==============================================================*/
/* Table: Poll                                                  */
/*==============================================================*/
create table Poll (
   idx                  int                  not null,
   pollName             nvarchar(50)          null,
   constraint PK_POLL primary key (idx)
)
go

/*==============================================================*/
/* Table: PollHeader                                            */
/*==============================================================*/
create table PollHeader (
   TIdd                 int                  null,
   idx                  int                  null,
   Head                 nvarchar(50)          not null,
   Firm                 int                  not null,
   DocType              int                  not null,
   changed              datetime             null,
   Status               int                  null,
   constraint PK_POLLHEADER primary key (Head, Firm, DocType)
)
go

/*==============================================================*/
/* Table: PollLink                                              */
/*==============================================================*/
create table PollLink (
   idx                  int                  not null,
   QuestionID           int                  not null,
   OrderNr              int                  null,
   constraint AK_KEY_1_POLLLINK unique (idx, QuestionID)
)
go

/*==============================================================*/
/* Table: PollQuestions                                         */
/*==============================================================*/
create table PollQuestions (
   QuestionID           int                  not null,
   PollQuestion         nvarchar(150)         null,
   constraint PK_POLLQUESTIONS primary key (QuestionID)
)
go

/*==============================================================*/
/* Table: PollResults                                           */
/*==============================================================*/
create table PollResults (
   QuestionId           int                  not null,
   Selections           nvarchar(50)          null,
   TextNum              nvarchar(50)          null,
   Idd                  int                  not null,
   Head                 nvarchar(50)          null,
   Firm                 int                  null,
   DocType              int                  null,
   Status               int                  null,
   constraint PK_POLLRESULTS primary key (Idd)
)
go

/*==============================================================*/
/* Table: Position                                              */
/*==============================================================*/
create table Position (
   Firm                 int                  not null,
   DocType              int                  not null,
   Head                 nvarchar(50)          not null,
   DelNote              nvarchar(50)          not null,
   Position             int                  not null,
   Code                 nvarchar(50)          null,
   Type                 int                  null,
   TIdd                 int                  null,
   UserIdx              int                  null,
   PositionLink         int                  null,
   txt                  int                  null,
   DTCreation           datetime             null,
   DTLastChange         datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   OFirm                nvarchar(50)          null,
   OCode                int                  null,
   OType                int                  null,
   AmountInv            float                null,
   Amount1              float                null,
   Amount2              float                null,
   Price1               float                null,
   Price2               float                null,
   AddParam1            nvarchar(50)          null,
   AddParam2            nvarchar(50)          null,
   UnitInv              int                  null,
   Unit1                int                  null,
   Unit2                int                  null,
   Status               int                  null,
   Amount1_disp         nvarchar(50)          null,
   Amount2_disp         nvarchar(50)          null,
   Discount             float                null,
   Discount2            float                null,
   Discount3            float                null,
   Notes                nvarchar(250)         null,
   SAPDiscountType     nvarchar(5)           null,
   SAPDiscount2Type    nvarchar(5)           null,
   SAPDiscount3Type    nvarchar(5)           null,
   SAPPacking          nvarchar(1)           null,
   PosWeight                int                  null,
   constraint PK_POSITION primary key (Position, Head, DelNote, Firm, DocType)
)
go

/*==============================================================*/
/* Index: I10002                                                */
/*==============================================================*/
create index I10002 on Position (
Firm ASC,
DocType ASC,
Head ASC,
DelNote ASC,
Position ASC,
Status ASC
)
go

/*==============================================================*/
/* Table: PriceCorrection_ProBit                                */
/*==============================================================*/
create table PriceCorrection_ProBit (
   Firm                 int                  not null,
   Link_Sub             nvarchar(50)          not null,
   Link_Obj             nvarchar(50)          not null,
   Type_Obj             int                  not null,
   VersionNum           int                  not null,
   DateStart            datetime             not null,
   DateStop             datetime             null,
   ProPriceList         nvarchar(5)           null,
   price                float                null,
   discount1            float                null,
   discount2            float                null,
   discount3            float                null,
   constraint PK_PRICECORRECTION_PROBIT primary key (Link_Sub, Link_Obj, Type_Obj, VersionNum, DateStart, Firm)
)
go

/*==============================================================*/
/* Index: Index_B                                               */
/*==============================================================*/
create index Index_B on PriceCorrection_ProBit (
Firm ASC,
Link_Sub ASC,
Link_Obj ASC,
Type_Obj ASC,
VersionNum ASC
)
go

/*==============================================================*/
/* Table: PriceCorrections_Price_ProBit                         */
/*==============================================================*/
create table PriceCorrections_Price_ProBit (
   ProPriceList         nvarchar(5)           not null,
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   VersionNum           int                  not null,
   price                float                null,
   DateStart            datetime             not null,
   constraint PK_PRICECORRECTIONS_PRICE_PROB primary key (ProPriceList, Code, Firm, Type, VersionNum, DateStart)
)
go

/*==============================================================*/
/* Table: PrintTemplates                                        */
/*==============================================================*/
create table PrintTemplates (
   TemplateIdd          int                  not null,
   Firm                 int                  not null,
   Name                 nvarchar(50)          null,
   Content              image       null,
   Status               int                  not null,
   constraint PK_PRINTTEMPLATES primary key  (TemplateIdd)
)
go

/*==============================================================*/
/* Table: Products                                              */
/*==============================================================*/
create table Products (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   Change               datetime             null,
   Name_full            nvarchar(250)         null,
   Categ1               nvarchar(50)          null,
   Categ2               nvarchar(50)          null,
   AddParam1            nvarchar(50)          null,
   AddParam2            nvarchar(50)          null,
   AddParam3            nvarchar(50)          null,
   AddParam4            nvarchar(50)          null,
   Count                nvarchar(50)          null,
   Unit1                int                  null,
   Unit2                int                  null,
   Status               int                  not null,
   Price1               float                null,
   Price2               float                null,
   Price3               float                null,
   Tax                  float                null,
   Pack                 float                null,
   proClass             nvarchar(10)          null,
   proGroup1            nvarchar(10)          null,
   proGroup2            nvarchar(10)          null,
   proGroup3            nvarchar(10)          null,
   proGroup4            nvarchar(10)          null,
   PriceSuggMin			float				 NULL,
   PriceSuggMax			float				 NULL,
   constraint PK_PRODUCTS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: QuestionLink                                          */
/*==============================================================*/
create table QuestionLink (
   QuestionID           int                  not null,
   GroupID              int                  not null,
   constraint AK_KEY_1_QUESTION unique (QuestionID, GroupID)
)
go

/*==============================================================*/
/* Table: QuestionTypes                                         */
/*==============================================================*/
create table QuestionTypes (
   QuestionType         int                  not null,
   TypeName             nvarchar(50)          null,
   constraint PK_QUESTIONTYPES primary key (QuestionType)
)
go

/*==============================================================*/
/* Table: RawScanAtl                                            */
/*==============================================================*/
create table RawScanAtl (
   Head                 nvarchar(50)          null,
   Scan                 nvarchar(50)          null,
   Price				float				  NULL,
   Action               bit                   NULL
)
go

/*==============================================================*/
/* Table: SAP_004                                               */
/*==============================================================*/
create table SAP_004 (
   Firm                 int                  not null,
   CondType            nvarchar(5)           not null,
   Obj_Code            nvarchar(50)          not null,
   Obj_Type             int                  not null,
   Rate                 float                null,
   RateUnit            nvarchar(5)           null,
   CondPriceUnit        float                null,
   PriceUnit           nvarchar(5)           null,
   FromDate             datetime             null,
   ToDate               datetime             not null,
   CondNr				int					 not null,
   insertTime           datetime             null,
   constraint PK_SAP_004 primary key (Firm, CondType, Obj_Code, Obj_Type, ToDate)
)
go

/*==============================================================*/
/* Table: SAP_305                                               */
/*==============================================================*/
create table SAP_305 (
   Firm                 int                  not null,
   CondType            nvarchar(5)           not null,
   Sub_Code            nvarchar(50)          not null,
   Sub_Type             int                  not null,
   Obj_Code            nvarchar(50)          not null,
   Obj_Type             int                  not null,
   Rate                 float                null,
   RateUnit            nvarchar(5)           null,
   CondPriceUnit        float                null,
   CondUnit            nvarchar(5)           null,
   FromDate             datetime             null,
   ToDate               datetime             not null,
   CondNr				int					 not null,
   insertTime           datetime             null,
   constraint PK_SAP_305 primary key (Firm, CondType, Sub_Code, Sub_Type, Obj_Code, Obj_Type, ToDate)
)
go

/*==============================================================*/
/* Table: SAP_907                                               */
/*==============================================================*/
create table SAP_907 (
   Firm                 int                  not null,
   CondType            nvarchar(5)           not null,
   Obj_Code            nvarchar(50)          not null,
   Obj_Type             int                  not null,
   PriceList            int                  not null,
   Rate                 float                null,
   RateUnit            nvarchar(5)           null,
   CondPriceUnit        float                null,
   CondUnit            nvarchar(5)           null,
   FromDate             datetime             null,
   ToDate               datetime             not null,
   CondNr				int					 not null,
   insertTime           datetime             null,
   constraint PK_SAP_907 primary key (Firm, CondType, Obj_Code, Obj_Type, PriceList, ToDate)
)
go

/*==============================================================*/
/* Table: SAP_908                                               */
/*==============================================================*/
create table SAP_908 (
   Firm                 int                  not null,
   Sub_Code            nvarchar(50)          not null,
   Sub_Type             int                  not null,
   CondType            nvarchar(5)           not null,
   Categ               nvarchar(50)          not null,
   Rate                 float                null,
   RateUnit            nvarchar(5)           null,
   CondPriceUnit        float                null,
   CondUnit            nvarchar(5)           null,
   FromDate             datetime             null,
   ToDate               datetime             not null,
   CondNr				int					 not null,
   insertTime           datetime             null,
   constraint PK_SAP_908 primary key (Firm, Sub_Code, Sub_Type, CondType, Categ, ToDate)
)
go

/*==============================================================*/
/* Table: SQLInsertValues                                       */
/*==============================================================*/
create table SQLInsertValues (
   Idd                  int                  not null,
   Val                  nvarchar(1500)        null,
   KeyColumn            int                  identity,
   constraint PK_SQLINSERTVALUES primary key (KeyColumn)
)
go

/*==============================================================*/
/* Table: SQLInserts                                            */
/*==============================================================*/
create table SQLInserts (
   Idd                  int                  not null,
   TableName            nvarchar(50)          null,
   ColumnNames          nvarchar(1000)        null,
   constraint PK_SQLINSERTS primary key (Idd)
)
go

/*==============================================================*/
/* Table: SerialAtl                                             */
/*==============================================================*/
create table SerialAtl (
   Code                 nvarchar(18)             not null,
   Serial               nvarchar(10)             not null,
   DueDate              datetime             null,
   AddDate              datetime             null,
   InsertDateTime       datetime             null,
   Status               int                  null,
   constraint PK_SERIALATL primary key (Code, Serial)
)
go

/*==============================================================*/
/* Index: Index_A                                               */
/*==============================================================*/
create index Index_A on SerialAtl (
Code ASC,
DueDate ASC
)
go

/*==============================================================*/
/* Index: Index_3                                               */
/*==============================================================*/
create index Index_3 on SerialAtl (
Code ASC,
AddDate ASC
)
go

/*==============================================================*/
/* Table: Settings                                              */
/*==============================================================*/
create table Settings (
   SettIdd              int                  not null,
   UserIdx              int                  null,
   TerminalIdx          int                  null,
   Sett_Type            int                  null,
   Firm                 int                  null,
   Type                 int                  null,
   Code                 nvarchar(50)          null,
   ErpDocIdd            nvarchar(50)          null,
   ErpVarIdd            nvarchar(50)          null,
   UserGroupIdx         int                  null,
   TerminalGroupIdx     int                  null,
   MenuGroupIdx         int                  null,
   SubIdx               int                  null,
   DT2_Idd              int                  null,
   Doc_Firm             int                  null,
   Doc_Type             int                  null,
   BDataIdx             int                  null,
   TL_Idd               int                  null,
   PrintTemplateIdd     int                  null,
   IValue               int                  null,
   CValue               nvarchar(50)          null,
   FValue               float                null,
   constraint PK_SETTINGS primary key (SettIdd)
)
go

/*==============================================================*/
/* Table: SettingsErpDoc                                        */
/*==============================================================*/
create table SettingsErpDoc (
   Firm                 int                  not null,
   ErpDocIdd            nvarchar(50)          not null,
   DocType              int                  null,
   InDocType              int                  null,
   DocName              nvarchar(50)          null,
   ShortDocName         nvarchar(50)          null,
   IssueWarehouseCode   nvarchar(50)          null,
   ReceiveWarehouseCode nvarchar(50)          null,
   Type                 int                  null,
   LastUsedDocumentNumber int                  null,
   Status               int                  null,
   IssueWarehouseType   int                  null,
   ReceiveWarehouseType int                  null,
   constraint PK_SETTINGSERPDOC primary key (Firm, ErpDocIdd)
)
go

/*==============================================================*/
/* Table: SettingsErpVariable                                   */
/*==============================================================*/
create table SettingsErpVariable (
   Firm                 int                  not null,
   ErpVarIdd            nvarchar(50)          not null,
   IValue               int                  null,
   CValue               nvarchar(50)          null,
   FValue               float                null,
   constraint PK_SETTINGSERPVARIABLE primary key (Firm, ErpVarIdd)
)
go

/*==============================================================*/
/* Table: Slink                                                 */
/*==============================================================*/
create table Slink (
   SLinkIdd             int                  not null,
   Source               int                  null,
   Destination          int                  null,
   Task                 int                  null,
   InsertDateTime       datetime             null,
   Chage                datetime             null,
   Status               int                  null,
   constraint PK_SLINK primary key (SLinkIdd)
)
go

/*==============================================================*/
/* Index: I00044                                                */
/*==============================================================*/
create index I00044 on Slink (
Source ASC
)
go

/*==============================================================*/
/* Index: I00045                                                */
/*==============================================================*/
create index I00045 on Slink (
Destination ASC
)
go

/*==============================================================*/
/* Index: I00046                                                */
/*==============================================================*/
create index I00046 on Slink (
Task ASC
)
go

/*==============================================================*/
/* Table: Stock                                                 */
/*==============================================================*/
create table Stock (
   SIdd                 int                  not null,
   LocCode              nvarchar(50)          null,
   LocFirm              int                  null,
   LocType              int                  null,
   OwnCode              nvarchar(50)          null,
   OwnFirm              int                  null,
   OwnType              int                  null,
   ObjectCode           nvarchar(50)          null,
   ObjectFirm           int                  null,
   ObjectType           int                  null,
   ObjectAmount1        float                null,
   ObjectUnit1          int                  null,
   ObjectAmount2        float                null,
   ObjectUnit2          int                  null,
   MicroLocType         int                  null,
   MicroLocCode         nvarchar(50)          null,
   MicroLocFirm         int                  null,
   Sub_Type             int                  null,
   TIdd                 int                  null,
   TL_Idd               int                  null,
   UserIdx              int                  null,
   ObjectSerial         nvarchar(50)          null,
   InsertDateTime       datetime             null,
   ObjectDateTime       datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Status               int                  not null,
   ChangeDateTime       datetime             null,
   SourceMicroLocCode   nvarchar(50)          null,
   SettIdd              int                  null,
   constraint PK_STOCK primary key (SIdd)
)
go

/*==============================================================*/
/* Index: I00051                                                */
/*==============================================================*/
create index I00051 on Stock (
LocCode ASC,
LocFirm ASC,
LocType ASC
)
go

/*==============================================================*/
/* Index: I00052                                                */
/*==============================================================*/
create index I00052 on Stock (
OwnCode ASC,
OwnFirm ASC,
OwnType ASC
)
go

/*==============================================================*/
/* Index: I00053                                                */
/*==============================================================*/
create index I00053 on Stock (
ObjectCode ASC,
ObjectFirm ASC,
ObjectType ASC
)
go

/*==============================================================*/
/* Index: I00054                                                */
/*==============================================================*/
create index I00054 on Stock (
Status ASC
)
go

/*==============================================================*/
/* Index: I00201                                                */
/*==============================================================*/
create index I00201 on Stock (
MicroLocType ASC,
MicroLocCode ASC,
MicroLocFirm ASC
)
go

/*==============================================================*/
/* Index: StockDeleteSupport                                    */
/*==============================================================*/
create index StockDeleteSupport on Stock (
SIdd ASC,
LocCode ASC,
OwnCode ASC,
OwnFirm ASC,
OwnType ASC,
ObjectCode ASC,
ObjectFirm ASC,
ObjectType ASC
)
go

/*==============================================================*/
/* Table: StockAddInfo                                          */
/*==============================================================*/
create table StockAddInfo (
   SIdd                 int                  not null,
   Type                 int                  null,
   Firm                 int                  null,
   Object_Code          nvarchar(50)          null,
   Subject_Code         nvarchar(50)          null,
   AddInt1              int                  null,
   AddInt2              int                  null,
   AddChar1             nvarchar(50)          null,
   AddChar2             nvarchar(50)          null,
   StockAddInfoIdd      int                  not null,
   Change               datetime             null,
   Status               int                  not null,
   constraint PK_STOCKADDINFO primary key  (StockAddInfoIdd)
)
go

/*==============================================================*/
/* Index: I00103                                                */
/*==============================================================*/
create index I00103 on StockAddInfo (
Type ASC,
Firm ASC,
Object_Code ASC
)
go

/*==============================================================*/
/* Index: I00104                                                */
/*==============================================================*/
create index I00104 on StockAddInfo (
Type ASC,
Firm ASC,
Subject_Code ASC
)
go

/*==============================================================*/
/* Index: I00105                                                */
/*==============================================================*/
create index I00105 on StockAddInfo (
SIdd ASC
)
go

/*==============================================================*/
/* Table: Stops                                                 */
/*==============================================================*/
create table Stops (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   Change               datetime             null,
   Status               int                  not null,
   Name_full            nvarchar(250)         null,
   constraint PK_STOPS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: SubMenu                                               */
/*==============================================================*/
create table SubMenu (
   SubIdx               int                  not null,
   MenuGroupIdx         int                  null,
   MenuIdx              int                  null,
   Type                 int                  not null,
   MenuOrder            int                  null,
   constraint PK_SUBMENU primary key  (SubIdx)
)
go

/*==============================================================*/
/* Table: SubParts                                              */
/*==============================================================*/
create table SubParts (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   Change               datetime             null,
   Status               int                  not null,
   Name_full            nvarchar(250)         null,
   constraint PK_SUBPARTS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: Subject                                               */
/*==============================================================*/
create table Subject (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Change               datetime             null,
   Type                 int                  not null,
   TIdd                 int                  null,
   TL_Idd               int                  null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Name                 nvarchar(50)          null,
   Name_ASCII           nvarchar(50)          null,
   Status               int                  not null,
   constraint PK_SUBJECT primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Index: I00056                                                */
/*==============================================================*/
create index I00056 on Subject (
Name ASC
)
go

/*==============================================================*/
/* Index: I00057                                                */
/*==============================================================*/
create index I00057 on Subject (
Status ASC
)
go

/*==============================================================*/
/* Index: I00058                                                */
/*==============================================================*/
create index I00058 on Subject (
Firm ASC,
Type ASC
)
go

/*==============================================================*/
/* Table: SubjectLists                                          */
/*==============================================================*/
create table SubjectLists (
   Code                 nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   Task                 int                  null,
   TIdd                 int                  null,
   TL_Idd               int                  null,
   Name_full            nvarchar(250)         null,
   Change               datetime             null,
   Status               int                  not null,
   constraint PK_SUBJECTLISTS primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: Subject_Interconnections                              */
/*==============================================================*/
create table Subject_Interconnections (
   DateTime1            datetime             null,
   DateTime2            datetime             null,
   SIC_Idd              int                  not null,
   Code                 nvarchar(50)          null,
   Firm                 int                  null,
   Type                 int                  null,
   Prev_Code            nvarchar(50)          null,
   Prev_Firm            int                  null,
   Prev_Type            int                  null,
   Curr_Code            nvarchar(50)          null,
   Curr_Firm            int                  null,
   Curr_Type            int                  null,
   Priority             int                  null,
   Status               int                  not null,
   constraint PK_SUBJECT_INTERCONNECTIONS primary key (SIC_Idd)
)
go

/*==============================================================*/
/* Index: I00059                                                */
/*==============================================================*/
create index I00059 on Subject_Interconnections (
Code ASC,
Firm ASC,
Type ASC
)
go

/*==============================================================*/
/* Index: I00060                                                */
/*==============================================================*/
create index I00060 on Subject_Interconnections (
Prev_Code ASC,
Prev_Firm ASC,
Prev_Type ASC
)
go

/*==============================================================*/
/* Index: I00061                                                */
/*==============================================================*/
create index I00061 on Subject_Interconnections (
Curr_Code ASC,
Curr_Firm ASC,
Curr_Type ASC
)
go

/*==============================================================*/
/* Table: Subject_Object_Interconnections                       */
/*==============================================================*/
create table Subject_Object_Interconnections (
   SIIC_Idd             int                  not null,
   Obj_Code             nvarchar(50)          null,
   Obj_Firm             int                  null,
   Obj_Type             int                  null,
   Sub_Code             nvarchar(50)          null,
   Sub_Firm             int                  null,
   Sub_Type             int                  null,
   TIdd                 int                  null,
   Own_Code             nvarchar(50)          null,
   Own_Firm             int                  null,
   Own_Type             int                  null,
   Add_Code             nvarchar(50)          null,
   Add_Firm             int                  null,
   Add_Type             int                  null,
   changed              datetime             null,
   Status               int                  null,
   constraint PK_SUBJECT_OBJECT_INTERCONNECT primary key (SIIC_Idd)
)
go

/*==============================================================*/
/* Index: I00064                                                */
/*==============================================================*/
create index I00064 on Subject_Object_Interconnections (
Obj_Code ASC,
Obj_Firm ASC,
Obj_Type ASC
)
go

/*==============================================================*/
/* Index: I00065                                                */
/*==============================================================*/
create index I00065 on Subject_Object_Interconnections (
Sub_Code ASC,
Sub_Firm ASC,
Sub_Type ASC
)
go

/*==============================================================*/
/* Table: Tasks                                                 */
/*==============================================================*/
create table Tasks (
   Task                 int                  not null,
   TimeStart            datetime             null,
   TimeLastUse          datetime             null,
   constraint PK_TASKS primary key (Task)
)
go

/*==============================================================*/
/* Table: Terminals                                             */
/*==============================================================*/
create table Terminals (
   TerminalIdx          int                  not null,
   TerminalID           nvarchar(50)          null,
   status               int                  null,
   constraint PK_TERMINALS primary key  (TerminalIdx)
)
go

/*==============================================================*/
/* Table: TerminalsGroups                                       */
/*==============================================================*/
create table TerminalsGroups (
   TerminalGroupIdx     int                  not null,
   TerminalIdx          int                  null,
   status               int                  null,
   TerminalGroupName    nvarchar(50)          null,
   constraint PK_TERMINALSGROUPS primary key (TerminalGroupIdx)
)
go

/*==============================================================*/
/* Table: TimeLine                                              */
/*==============================================================*/
create table TimeLine (
   TL_Idd               int                  not null,
   Firm                 int                  null,
   Type                 int                  null,
   Code                 nvarchar(50)          null,
   Name                 nvarchar(50)          null,
   Description          nvarchar(50)          null,
   TimeFrom             datetime             null,
   TimeTo               datetime             null,
   TimeAdd1             datetime             null,
   IValue               int                  null,
   CValue               nvarchar(50)          null,
   FValue               float                null,
   status               int                  null,
   constraint PK_TIMELINE primary key (TL_Idd)
)
go

/*==============================================================*/
/* Table: Txt                                                   */
/*==============================================================*/
create table Txt (
   Txt                  nvarchar(500)         null,
   TIdd                 int                  not null,
   Change               datetime             null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Status               int                  null,
   constraint PK_TXT primary key (TIdd)
)
go

/*==============================================================*/
/* Table: Txt_Add                                               */
/*==============================================================*/
create table Txt_Add (
   TIdd                 int                  not null,
   Idd                  int                  not null,
   Txt                  nvarchar(500)         null,
   constraint PK_TXT_ADD primary key (TIdd, Idd)
)
go

/*==============================================================*/
/* Table: Types                                                 */
/*==============================================================*/
create table Types (
   Type                 int                  not null,
   GroupIdx             int                  null,
   DocumentTitle        nvarchar(50)          null,
   DocumentIdent        nvarchar(50)          null,
   Status               int                  null,
   constraint PK_TYPES primary key (Type)
)
go

/*==============================================================*/
/* Table: TypesGroups                                           */
/*==============================================================*/
create table TypesGroups (
   GroupIdx             int                  not null,
   Name                 nvarchar(100)         null,
   Description          nvarchar(200)         null,
   constraint PK_TYPESGROUPS primary key (GroupIdx)
)
go

/*==============================================================*/
/* Table: Users                                                 */
/*==============================================================*/
create table Users (
   UserIdx              int                  not null,
   Firm                 int                  null,
   Type                 int                  null,
   UserName             nvarchar(50)          null,
   Password             nvarchar(50)          null,
   Code                 nvarchar(50)          null,
   Serial               nvarchar(50)          null,
   SecLevel             nvarchar(50)          null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Status               int                  null,
   sapCashier          nvarchar(5)           null,
   sapSalesGroup       nvarchar(5)           null,
   sapSalesOffice      nvarchar(5)           null,
   constraint PK_USERS primary key (UserIdx)
)
go

/*==============================================================*/
/* Index: I00078                                                */
/*==============================================================*/
create index I00078 on Users (
Code ASC
)
go

/*==============================================================*/
/* Table: UsersGroups                                           */
/*==============================================================*/
create table UsersGroups (
   UserGroupIdx         int                  not null,
   UserIdx              int                  null,
   status               int                  null,
   UserGroupName4       nvarchar(50)          null,
   constraint PK_USERSGROUPS primary key (UserGroupIdx)
)
go

/*==============================================================*/
/* Table: Variable                                              */
/*==============================================================*/
create table Variable (
   Firm                 int                  not null,
   Type                 int                  not null,
   Name                 nvarchar(350)         not null,
   IValue               int                  null,
   CValue               nvarchar(350)         null,
   MRead1               bigint               null,
   MRead2               bigint               null,
   MWrite1              bigint               null,
   MWrite2              bigint               null,
   Status               int                  null,
   constraint PK_VARIABLE primary key (Firm, Type, Name)
)
go


/*==============================================================*/
/* Table: atlantic_object_add                                   */
/*==============================================================*/
create table atlantic_object_add (
   Code                nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   prim                nvarchar(50)          null,
   sek                 nvarchar(50)          null,
   constraint PK_ATLANTIC_OBJECT_ADD primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: atlantic_subject_add                                  */
/*==============================================================*/
create table atlantic_subject_add (
   Code                nvarchar(50)          not null,
   Firm                 int                  not null,
   Type                 int                  not null,
   tip_pr_m            nvarchar(50)          null,
   regija              nvarchar(50)          null,
   trgovina            nvarchar(50)          null,
   teren               nvarchar(50)          null,
   constraint PK_ATLANTIC_SUBJECT_ADD primary key (Code, Firm, Type)
)
go

/*==============================================================*/
/* Table: atlntic_pivot                                         */
/*==============================================================*/
create table atlntic_pivot (
   Sub_Code            nvarchar(50)          not null,
   Sub_Firm             int                  not null,
   Sub_Type             int                  not null,
   Obj_Code            nvarchar(50)          not null,
   Obj_Firm             int                  not null,
   Obj_Type             int                  not null,
   UserIdx              int                  not null,
   Firm                 int                  not null,
   listing              bit                  null,
   prisotnost           bit                  null,
   obvezni              bit                  null,
   oos                  bit                  null,
   constraint PK_ATLNTIC_PIVOT primary key (Sub_Code, Sub_Firm, Sub_Type, Obj_Code, Obj_Firm, Obj_Type, UserIdx, Firm)
)
go

/*==============================================================*/
/* Table: atlntic_users                                         */
/*==============================================================*/
create table atlntic_users (
   UserIdx              int                  not null,
   Firm                 int                  not null,
   Teren               nvarchar(100)         null,
   constraint PK_ATLNTIC_USERS primary key (UserIdx, Firm)
)
go

/*==============================================================*/
/* Table: transfer_in                                           */
/*==============================================================*/
create table transfer_in (
   priority             smallint             not null,
   xmldata              image       null,
   constraint PK_TRANSFER_IN primary key (priority)
)
go

/*==============================================================*/
/* Table: transfer_log                                          */
/*==============================================================*/
create table transfer_log (
   eventTime            datetime             not null,
   eventDirection       nvarchar(3)           null,
   txt                  nvarchar(300)         not null,
   constraint PK_TRANSFER_LOG primary key  (eventTime, txt)
)
go

/*==============================================================*/
/* Table: transfer_out                                          */
/*==============================================================*/
create table transfer_out (
   priority             smallint             not null,
   Firm                 int                  null,
   xmldata              image       null,
   constraint PK_TRANSFER_OUT primary key (priority)
)
go

/*==============================================================*/
/* Table: PoslovniProstor                                       */
/*==============================================================*/
create table PoslovniProstor
(
Firm					int				not null,
Head					nvarchar(50)		not null,
DocType					int				not null,
Oib						nvarchar(11)		not null,
OznPoslProstora			nvarchar(20)		not null,
Ulica					nvarchar(100)	null,
KucniBroj				nvarchar(4)		null,
KucniBrojDodatak		nvarchar(4)		null,
BrojPoste				nvarchar(12)		null,
Naselje					nvarchar(35)		null,
Opcina					nvarchar(35)		null,
OstaliTipoviPP			nvarchar(100)	null,
RadnoVrijeme			nvarchar(1000)	not null,
DatumPocetkaPrimjene	datetime		not null,
OznakaZatvaranja		nvarchar(1)		null,
SpecNamj				nvarchar(1000)	null,
Poslan					int				not null,
constraint PK_POSLOVNIPROSTOR primary key (Head, Firm, DocType)
)
go

/*==============================================================*/
/* Table: Racun                                         		*/
/*==============================================================*/
create table Racun
(
Firm					int				not null,
Head					nvarchar(50)		not null,
DocType					int				not null,
Oib						nvarchar(11)		not null,
USustPdv				bit			not null,
DatumVrijeme			datetime		not null,
OznSlijed				nvarchar(1)			not null,
BrOznRac				nvarchar(20)		not null,
OznPosPr				nvarchar(20)		not null,
OznNapUr				nvarchar(20)		not null,
IznosOslobPdv			float		null,
IznosMarza				float		null,
IznosNePodlOpor			float		null,
IznosUkupno				float		not null,
NacinPlac				nvarchar(1)			not null,
OibOper					nvarchar(11)		not null,
ZastKod					nvarchar(32)		not null,
NakDost					bit			not null,
ParagonBrRac			nvarchar(100)	null,
SpecNamj				nvarchar(1000)	null,
Jir						nvarchar(36)		null,
constraint PK_RACUN primary key (Head, Firm, DocType)
)
go

/*==============================================================*/
/* Table: Pdv                                         			*/
/*==============================================================*/
create table Pdv
(
Firm					int				not null,
Head					nvarchar(50)		not null,
DocType					int				not null,
PoreznaStopa			float		not null,
Osnovica				float		not null,
IznosPoreza				float		not null
)
go

/*==============================================================*/
/* Table: Pnp                                         			*/
/*==============================================================*/
create table Pnp
(
Firm					int				not null,
Head					nvarchar(50)		not null,
DocType					int				not null,
PoreznaStopa			float		not null,
Osnovica				float		not null,
IznosPoreza				float		not null
)
go

/*==============================================================*/
/* Table: OstaliPor                                         	*/
/*==============================================================*/
create table OstaliPor
(
Firm					int				not null,
Head					nvarchar(50)		not null,
DocType					int				not null,
NazivPoreza				nvarchar(100)	not null,
PoreznaStopa			float		not null,
Osnovica				float		not null,
IznosPoreza				float		not null
)
go

/*==============================================================*/
/* Table: Naknada                                         		*/
/*==============================================================*/
create table Naknada
(
Firm					int				not null,
Head					nvarchar(50)		not null,
DocType					int				not null,
NazivNaknade			nvarchar(100)	not null,
IznosNaknade			float			not null
)
go