-
Notifications
You must be signed in to change notification settings - Fork 2
/
queryscripts.sql
147 lines (118 loc) · 2.84 KB
/
queryscripts.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
/*Order Management table query*/
SELECT
o.OrderID,
CONCAT(c.CustomerFname, ' ', c.CustomerLname) AS CustomerName,
o.OrderStartDate,
o.OrderDeadline,
o.OrderStatusCode AS Status
FROM
orders o
INNER JOIN customers c ON o.customerid = c.customerID
where o.isremoved = 0 order by o.orderId asc;
/*Payment Receipts Table*/
SELECT
r.ReceiptID,
p.OrderID,
p.PaymentMethod,
r.ReceiptAmountPaid,
r.PaymentDate
From
Payment_Receipts r
INNER JOIN payment_plans p on r.PlanID = p.planID
where r.isremoved = 0 order by r.ReceiptID asc;
/* Order Details Page */
/* Customer Information */
select
concat(customerFname, ' ', CustomerLname) as 'Customer Name',
CustomerEmail as 'Email',
CustomerPhone as 'Phone Number'
from customers where
customerID = 1;
/* Order Information */
select
OrderStartDate as 'Order Date',
OrderDeadline as 'Deadline',
OrderStatusCode as 'Status'
from orders where
orderID = 1;
/* Ordered Products */
select
ProductID,
productDescription,
productDimenstions,
ProductQuantity,
ProductPrice,
ProductStatusCode
from products where
orderID = 1 and isremoved = 0;
/* payment Plan */
select
PaymentMethod,
DueDate,
PaymentStatus,
TotalAmount,
AmountPaid,
Balance
from payment_Plans where
orderID = 1 and isremoved = 0;
/* Related Receipts Table */
select
ReceiptID,
ReceiptAmountPaid,
PaymentDate
from Payment_Receipts where
planID = 1 AND isremoved = 0;
/* Dashboard */
/* Analytics */
SELECT
SUM(ReceiptAmountPaid) AS 'Monthly Sales'
FROM
Payment_Receipts
WHERE
PaymentDate >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
AND PaymentDate <= CURDATE();
/* Total Orders */
SELECT
count(OrderID) as 'Total Orders'
FROM
orders where
isremoved = 0;
/* Total Sales */
SELECT
SUM(ReceiptAmountPaid) As 'Total Sales'
From
Payment_Receipts
where
isremoved = 0;
/* Recent Orders */
select
o.orderID as 'Order ID',
concat(c.customerFname, ' ', c.customerLname) as 'Customer Name',
o.orderStartDate as 'Order Date',
pp.TotalAmount as 'Amount',
o.OrderDeadline as 'Deadline',
o.OrderStatusCode as 'Status'
From
orders o
INNER JOIN payment_Plans pp on pp.orderID = o.orderID
INNER JOIN customers c on o.customerID = c.customerID
Order by o.OrderDeadline asc Limit 5;
insert into payment_receipts (
PlanID,
ReceiptImagePath,
Haspicture,
ReceiptAmountpaid,
paymentDate,
PaymentProcessor,
PaymentProcessorReferenceNumber,
Isremoved)
values (
1,
'sadsdas',
1,
100,
CURDATE(),
'processor1',
23131,
0
);