-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheckout.cpp
190 lines (149 loc) · 6.64 KB
/
checkout.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include"mainwindow.h"
#include <QProgressDialog>
#include <QDebug>
#include <QCheckBox>
void MainWindow::checkout(int room){
QVBoxLayout *layout = new QVBoxLayout;
Database db;
Guest guest = db.getGuestDetailByRoomNo(room);
Guest_id_cout = guest.getID();
Guest_room_cout = guest.getRoomNo();
if(guest.getID() == NULL)
{ infoLabel = new QLabel();
infoLabel->setText("No user");
}
else{
infoLabel = new QLabel();
infoLabel->setText("Bill For HMS");
}
infoLabel->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
infoLabel->setAlignment(Qt::AlignCenter);
QWidget *userForm = new QWidget(bottom_half); // QWidget(widget)
QGridLayout *user_formLayout = new QGridLayout(); // Defines grid layout for name
user_formLayout->setColumnMinimumWidth(1,300);
// Form Fields Start
//Hint Text
QLabel *nameHint = new QLabel("Name");
nameHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *emailHint = new QLabel("Email");
emailHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *phoneHint = new QLabel("Phone No.");
phoneHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *addressHint = new QLabel("Address");
addressHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *nationalityHint = new QLabel("Nationality");
nationalityHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *TotalPayHint = new QLabel("Total Amount");
TotalPayHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *PaidPayHint = new QLabel("Paid Amount");
PaidPayHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *DuePayHint = new QLabel("Due Amount");
DuePayHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
QLabel *PayHint = new QLabel("Pay:");
PayHint->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
// Input Forms
QLabel *custo_name = new QLabel();//this refers to the MainWindow class
QLabel *custo_email = new QLabel();
QLabel *custo_phone = new QLabel();
QLabel *custo_address = new QLabel();
QLabel *custo_nationality = new QLabel();
QLabel *Total = new QLabel();
Paid = new QLabel();
Due = new QLabel();
Pay_amount = new QLineEdit();
Pay_amount->setFixedHeight(40);
Pay_amount->setClearButtonEnabled(true);
Pay_amount->setPlaceholderText("Pay Here");
custo_name->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
custo_email->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
custo_phone->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
custo_address->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
custo_nationality->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
Total->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
Paid->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
Due->setStyleSheet("*{font-weight:bold;font-size:15px;padding:10px;}");
custo_name->setText(guest.getName());
custo_email->setText(guest.getEmail());
custo_phone->setText(guest.getContact());
custo_address->setText(guest.getAddress());
custo_nationality->setText(guest.getIdentity());
Total->setNum(guest.getTotalAmount());
Paid->setNum(guest.getPaidAmount());
Due->setNum(guest.getDueAmount());
//Adding widgets in the userForm layout
user_formLayout-> setHorizontalSpacing(30);
user_formLayout->addWidget(nameHint,0,0);
user_formLayout->addWidget(custo_name,0,1);
user_formLayout->addWidget(emailHint,1,0);
user_formLayout->addWidget(custo_email,1,1);
user_formLayout->addWidget(phoneHint,2,0);
user_formLayout->addWidget(custo_phone,2,1);
user_formLayout->addWidget(addressHint,3,0);
user_formLayout->addWidget(custo_address,3,1);
user_formLayout->addWidget(nationalityHint,4,0);
user_formLayout->addWidget(custo_nationality,4,1);
user_formLayout->addWidget(TotalPayHint,5,0);
user_formLayout->addWidget(Total,5,1);
user_formLayout->addWidget(PaidPayHint,6,0);
user_formLayout->addWidget(Paid,6,1);
user_formLayout->addWidget(DuePayHint,7,0);
user_formLayout->addWidget(Due,7,1);
user_formLayout->addWidget(PayHint,8,0);
user_formLayout->addWidget(Pay_amount,8,1);
user_formLayout->setColumnStretch(8,1);
userForm->setLayout(user_formLayout);
QWidget *Button_widget = new QWidget(bottom_half); //QWidget(widget)
QGridLayout *buttonLayout = new QGridLayout();
QPushButton *checkout_nowButton = new QPushButton("Check out");
checkout_nowButton->setStyleSheet("*{background:red;height:30px;}");
connect(checkout_nowButton,SIGNAL(clicked(bool)),this,SLOT(checkout_now()));
connect(checkout_nowButton,SIGNAL(clicked(bool)),this,SLOT(dashboard()));
// GO Back Button
QPushButton *BackButton = new QPushButton("Back");
BackButton->setStyleSheet("*{background:red;height:30px;}");
BackButton->adjustSize();
connect(BackButton,SIGNAL(clicked()),this,SLOT(Bill()));
QPushButton *PayButton = new QPushButton("Pay");
PayButton->setStyleSheet("*{background:red;height:30px;}");
PayButton->adjustSize();
connect(PayButton,SIGNAL(clicked()),this,SLOT(payNow()));
//adding button widgets to buttonlayout
buttonLayout->addWidget(BackButton,0,0,Qt::AlignLeft);
buttonLayout->addWidget(PayButton,0,1,Qt::AlignLeft);
buttonLayout->addWidget(checkout_nowButton,0,3,Qt::AlignRight);
buttonLayout->setColumnStretch(2,2);
Button_widget->setLayout(buttonLayout);
layout->addWidget(infoLabel);
layout->addWidget(userForm);
layout->addWidget(Button_widget);
bottom_half->setLayout(layout);
}
void MainWindow::checkout_now(){
Database db;
QMessageBox msgBox;
if (db.isCheckOutAble(Guest_id_cout))
{
db.guestCheckOut(Guest_id_cout, Guest_room_cout);
msgBox.setText("Check Out successful");
}
else
{
msgBox.setText("Please check your amount and try again");
}
msgBox.exec();
}
void MainWindow::payNow(){
Database db;
if(db.payAmount(Pay_amount->text().toInt(), Guest_id_cout)){
QMessageBox msgBox;
msgBox.setText("Amount Paid successfully");
msgBox.exec();
Guest guest = db.getGuestDetailByID(Guest_id_cout);
Due->setNum(guest.getDueAmount());
Paid->setNum(guest.getPaidAmount());
}else{
QMessageBox msgBox;
msgBox.setText("Error has occured");
msgBox.exec();
}
}