-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbi-Orders-view.sql
173 lines (160 loc) · 3.15 KB
/
bi-Orders-view.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/****** Object: View [bi].[Customer] Script Date: 2/8/2023 9:36:11 PM ******/
CREATE SCHEMA [bi]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [bi].[Customer]
AS
SELECT
M.Id as CustomerId,
M.CreatedDate,
M.Name,
M.FirstName,
M.MiddleName,
M.LastName,
M.FullName,
M.Status,
A.StoreId
FROM
dbo.Member AS M
INNER JOIN dbo.AspNetUsers AS A ON M.Id = A.Id
WHERE
(
M.Discriminator = 'ContactEntity'
)
GO
/****** Object: View [bi].[Orders] Script Date: 2/8/2023 9:36:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [bi].[Orders]
AS
SELECT
Id as OrderId,
CreatedDate,
Number AS OrderNumber,
Status,
SubTotal,
ShippingTotal,
TaxTotal,
PaymentTotal,
FeeTotal,
DiscountTotal,
Total,
Currency,
SubTotal + ShippingTotal + TaxTotal + PaymentTotal + FeeTotal - DiscountTotal AS CalculatedTotal,
CustomerId,
StoreId,
OrganizationId
FROM
dbo.CustomerOrder
GO
/****** Object: View [bi].[Organization] Script Date: 2/8/2023 9:36:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [bi].[Organization]
AS
SELECT
Id As OrganizationId,
CreatedDate,
Name,
Status
FROM
dbo.Member AS M
WHERE
(
Discriminator = 'OrganizationEntity'
)
GO
/****** Object: View [bi].[Product] Script Date: 2/8/2023 9:36:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [bi].[Product]
AS
SELECT
dbo.Item.Code AS Sku,
dbo.Item.Name,
dbo.Item.Id,
dbo.Item.ProductType,
dbo.Category.Name AS Category,
dbo.Category.Id AS CategoryId,
(
SELECT
TOP (1) Url
FROM
dbo.CatalogImage
WHERE
(ItemId = dbo.Item.Id)
ORDER BY
SortOrder
) AS ProductImage,
(
SELECT
TOP (1) Url
FROM
dbo.CatalogImage
WHERE
(CategoryId = dbo.Category.Id)
ORDER BY
SortOrder
) AS CategoryImage
FROM
dbo.Item
INNER JOIN dbo.Category ON dbo.Item.CategoryId = dbo.Category.Id
GO
/****** Object: View [bi].[Sales] Script Date: 2/8/2023 9:36:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [bi].[Sales]
AS
SELECT
dbo.OrderLineItem.Id as SaleId,
dbo.OrderLineItem.CreatedDate,
dbo.OrderLineItem.Currency,
dbo.OrderLineItem.Price,
dbo.OrderLineItem.DiscountAmount,
(
dbo.OrderLineItem.Price - dbo.OrderLineItem.DiscountAmount
)* dbo.OrderLineItem.Quantity AS Amount,
dbo.OrderLineItem.Quantity,
dbo.OrderLineItem.Sku,
dbo.CustomerOrder.Number AS OrderNumber,
dbo.CustomerOrder.Number AS OrderId,
dbo.CustomerOrder.CustomerId,
dbo.CustomerOrder.StoreId,
dbo.CustomerOrder.OrganizationId,
dbo.CustomerOrder.Status
FROM
dbo.OrderLineItem
INNER JOIN dbo.CustomerOrder ON dbo.OrderLineItem.CustomerOrderId = dbo.CustomerOrder.Id
GO
/****** Object: View [bi].[Store] Script Date: 2/8/2023 9:36:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [bi].[Store]
AS
SELECT
Id as StoreId,
Name,
Description,
Url,
StoreState,
TimeZone,
Country,
Region,
DefaultLanguage,
DefaultCurrency
FROM
dbo.Store
GO