narsil/Sql/2014.10.12 Step 1. Create New DB Schema.sql
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

319 lines
20 KiB
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

USE [Sales]
GO
create table dbo.Vouchers (
VoucherID UNIQUEIDENTIFIER not null,
[Date] DATETIME not null,
Pax INT null,
UserID UNIQUEIDENTIFIER not null,
CreationDate DATETIME not null,
LastEditDate DATETIME not null,
BillID NVARCHAR(255) not null,
TableID NVARCHAR(255) not null,
WaiterID UNIQUEIDENTIFIER not null,
CustomerID UNIQUEIDENTIFIER not null,
Narration NVARCHAR(255) null,
Void BIT not null,
VoidReason NVARCHAR(255) null,
Printed BIT not null,
VoucherType INT not null,
KotID NVARCHAR(255) not null,
primary key (VoucherID)
)
create table dbo.Auth_Users (
UserID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
MsrString NVARCHAR(255) null,
Password NVARCHAR(255) not null,
LockedOut BIT not null,
primary key (UserID)
)
create table dbo.Waiters (
WaiterID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
primary key (WaiterID)
)
create table dbo.Customers (
CustomerID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
Address NVARCHAR(255) null,
Important BIT null,
Phone NVARCHAR(255) null,
Remarks NVARCHAR(255) null,
primary key (CustomerID)
)
create table dbo.Auth_UserGroups (
UserGroupID UNIQUEIDENTIFIER not null,
UserID UNIQUEIDENTIFIER not null,
GroupID UNIQUEIDENTIFIER not null,
primary key (UserGroupID)
)
create table dbo.Kots (
KotID UNIQUEIDENTIFIER not null,
VoucherID UNIQUEIDENTIFIER not null,
Code NVARCHAR(255) not null unique,
TableID NVARCHAR(255) not null,
Printed BIT not null,
[Date] DATETIME not null,
UserID UNIQUEIDENTIFIER not null,
primary key (KotID)
)
create table dbo.Reprints (
ReprintID UNIQUEIDENTIFIER not null,
UserID UNIQUEIDENTIFIER not null,
[Date] DATETIME not null,
VoucherID UNIQUEIDENTIFIER not null,
primary key (ReprintID)
)
create table dbo.Inventories (
InventoryID UNIQUEIDENTIFIER not null,
KotID UNIQUEIDENTIFIER not null,
ProductID UNIQUEIDENTIFIER not null,
Quantity DECIMAL(19,5) not null,
Price DECIMAL(19,5) not null,
FullPrice DECIMAL(19,5) not null,
ServiceCharge DECIMAL(19,5) not null,
IsScTaxable BIT not null,
ServiceTaxRate DECIMAL(19,5) not null,
VatRate DECIMAL(19,5) not null,
ServiceTaxID UNIQUEIDENTIFIER not null,
VatID UNIQUEIDENTIFIER not null,
Discount DECIMAL(19,5) not null,
Amount AS (case when [IsScTaxable]=(1) then ((([Quantity]*[Price])*((1)-[Discount]))*((1)+[ServiceCharge]))*(((1)+[ServiceTaxRate])+[VatRate]) else (([Quantity]*[Price])*((1)-[Discount]))*((((1)+[ServiceCharge])+[ServiceTaxRate])+[VatRate]) end),
primary key (InventoryID)
)
create table dbo.InventoryModifiers (
InventoryModifierID UNIQUEIDENTIFIER not null,
InventoryID UNIQUEIDENTIFIER not null,
ModifierID UNIQUEIDENTIFIER not null,
primary key (InventoryModifierID)
)
create table dbo.Auth_Groups (
GroupID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
primary key (GroupID)
)
create table dbo.Auth_RoleGroups (
RoleGroupID UNIQUEIDENTIFIER not null,
RoleID UNIQUEIDENTIFIER not null,
GroupID UNIQUEIDENTIFIER not null,
primary key (RoleGroupID)
)
create table dbo.Products (
ProductID UNIQUEIDENTIFIER not null,
Code INT null,
Name NVARCHAR(255) not null,
Units NVARCHAR(255) not null,
ProductGroupID UNIQUEIDENTIFIER null,
VatID UNIQUEIDENTIFIER null,
ServiceTaxID UNIQUEIDENTIFIER null,
ServiceCharge DECIMAL(19,5) not null,
IsScTaxable BIT not null,
Price DECIMAL(19,5) not null,
FullPrice DECIMAL(19,5) not null,
Discontinued BIT not null,
SortOrder INT not null,
BaseCode INT not null,
Quantity DECIMAL(19,5) not null,
primary key (ProductID),
unique (Name, Units)
)
create table dbo.Modifiers (
ModifierID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
ShowInBill BIT not null,
Price DECIMAL(19,5) not null,
primary key (ModifierID)
)
create table dbo.ProductGroupModifiers (
ProductGroupModifierID UNIQUEIDENTIFIER not null,
ProductGroupID UNIQUEIDENTIFIER null,
ModifierID UNIQUEIDENTIFIER null,
ShowAutomatically BIT not null,
primary key (ProductGroupModifierID)
)
create table dbo.Auth_Roles (
RoleID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
primary key (RoleID)
)
create table dbo.ProductGroups (
ProductGroupID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
DiscountLimit DECIMAL(19,5) not null,
IsModifierCompulsory BIT not null,
Discontinued BIT not null,
SortOrder INT not null,
GroupType NVARCHAR(255) not null,
primary key (ProductGroupID)
)
create table dbo.PrintLocations (
PrintLocationID UNIQUEIDENTIFIER not null,
ProductGroupID UNIQUEIDENTIFIER null,
Location NVARCHAR(255) null,
Printer NVARCHAR(255) null,
Copies INT null,
CutCode NVARCHAR(255) null,
primary key (PrintLocationID)
)
create table dbo.Taxes (
TaxID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
Rate DECIMAL(19,5) not null,
primary key (TaxID)
)
create table dbo.VoucherSettlements (
VoucherSettlementID UNIQUEIDENTIFIER not null,
VoucherID UNIQUEIDENTIFIER not null,
Settled INT not null,
Amount DECIMAL(19,5) not null,
primary key (VoucherSettlementID)
)
create table dbo.FoodTables (
FoodTableID UNIQUEIDENTIFIER not null,
Name NVARCHAR(255) not null unique,
Location NVARCHAR(255) null,
Status NVARCHAR(255) null,
SortOrder INT null,
VoucherID UNIQUEIDENTIFIER null,
primary key (FoodTableID)
)
alter table dbo.Vouchers
add constraint FK415A8D77B9E9332A
foreign key (UserID)
references dbo.Auth_Users
alter table dbo.Vouchers
add constraint FK415A8D773E16E17E
foreign key (WaiterID)
references dbo.Waiters
alter table dbo.Vouchers
add constraint FK415A8D7737EDAED4
foreign key (CustomerID)
references dbo.Customers
alter table dbo.Auth_UserGroups
add constraint FKF726684AB9E9332A
foreign key (UserID)
references dbo.Auth_Users
alter table dbo.Auth_UserGroups
add constraint FKF726684A26F423BC
foreign key (GroupID)
references dbo.Auth_Groups
alter table dbo.Kots
add constraint FKF9C1219798E59CD2
foreign key (VoucherID)
references dbo.Vouchers
alter table dbo.Kots
add constraint FKF9C12197B9E9332A
foreign key (UserID)
references dbo.Auth_Users
alter table dbo.Reprints
add constraint FK5F5D4BA5B9E9332A
foreign key (UserID)
references dbo.Auth_Users
alter table dbo.Reprints
add constraint FK5F5D4BA598E59CD2
foreign key (VoucherID)
references dbo.Vouchers
alter table dbo.Inventories
add constraint FK8C0CFB22DB70F42
foreign key (KotID)
references dbo.Kots
alter table dbo.Inventories
add constraint FK8C0CFB223F88CAB6
foreign key (ProductID)
references dbo.Products
alter table dbo.Inventories
add constraint FK8C0CFB221DECC269
foreign key (ServiceTaxID)
references dbo.Taxes
alter table dbo.Inventories
add constraint FK8C0CFB22EB4DE5BC
foreign key (VatID)
references dbo.Taxes
alter table dbo.InventoryModifiers
add constraint FK80820FB4BA29671A
foreign key (InventoryID)
references dbo.Inventories
alter table dbo.InventoryModifiers
add constraint FK80820FB4C0C73B24
foreign key (ModifierID)
references dbo.Modifiers
alter table dbo.Auth_RoleGroups
add constraint FK656F81475D2D5938
foreign key (RoleID)
references dbo.Auth_Roles
alter table dbo.Auth_RoleGroups
add constraint FK656F814726F423BC
foreign key (GroupID)
references dbo.Auth_Groups
alter table dbo.Products
add constraint FK4065562A95976D16
foreign key (ProductGroupID)
references dbo.ProductGroups
alter table dbo.Products
add constraint FK4065562AEB4DE5BC
foreign key (VatID)
references dbo.Taxes
alter table dbo.Products
add constraint FK4065562A1DECC269
foreign key (ServiceTaxID)
references dbo.Taxes
alter table dbo.ProductGroupModifiers
add constraint FK445AB60E95976D16
foreign key (ProductGroupID)
references dbo.ProductGroups
alter table dbo.ProductGroupModifiers
add constraint FK445AB60EC0C73B24
foreign key (ModifierID)
references dbo.Modifiers
alter table dbo.PrintLocations
add constraint FK8AE807795976D16
foreign key (ProductGroupID)
references dbo.ProductGroups
alter table dbo.VoucherSettlements
add constraint FK61CD43EC98E59CD2
foreign key (VoucherID)
references dbo.Vouchers