-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient_Add_Service.cpp
319 lines (264 loc) · 12 KB
/
Client_Add_Service.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include "QMessageBox"
#include "QtSql"
#include "Client_Add_Service.h"
#include "ui_Client_Add_service.h"
#include "Stock_Parts_Selection.h"
#include "Service_Update_Description.h"
#include "Main_Window.h"
Client_Add_Service::Client_Add_Service(QWidget *parent) :
QDialog(parent),
ui(new Ui::Client_Add_Service)
{
ui->setupUi(this);
LoadSettings();
ui->txt_Servicedescription->setReadOnly(true);
ui->line_ServiceShortDescription->setReadOnly(true);
ui->tabWidget->setCurrentIndex(0);//Focus on the first tab//
}
Client_Add_Service::~Client_Add_Service()
{
SaveSettings();
delete ui;
}
QString Client_Add_Service::getServiceID() const
{
return ServiceID;
}
void Client_Add_Service::setServiceID(const QString &value)
{
ServiceID = value;
}
QString Client_Add_Service::getCarID() const
{
return CarID;
}
void Client_Add_Service::setCarID(const QString &value)
{
CarID = value;
}
QString Client_Add_Service::getClientid() const
{
return clientid;
}
void Client_Add_Service::setClientid(const QString &value)
{
clientid = value;
}
void Client_Add_Service::Add_Service_Description_Text(){
QSqlQueryModel* model = new QSqlQueryModel;
model->setQuery("SELECT Service_Description, Service_Short_Description FROM Service WHERE Service_id = " + ServiceID);
ui->line_ServiceShortDescription->setText(model->data(model->index(0, 1)).toString());
ui->txt_Servicedescription->setText(model->data(model->index(0, 0)).toString());
}
void Client_Add_Service::Load_Parts_And_Service_Costs_Grid(){
QSqlQueryModel* model = new QSqlQueryModel;
model->setQuery("SELECT ServicePartsUsed_id,"
" Part_id,"
" Part_Quantity,"
" Part_Name, "
" Part_Sell_Value_With_Interest_Rate"
" FROM Part p JOIN ServicePartsUsed pu "
" ON pu.Used_Part_ID = p.Part_id "
" AND pu.Used_On_What_Service_id = " + ServiceID);
model->setHeaderData(0, Qt::Horizontal, tr("Used Service Part ID"));
model->setHeaderData(1, Qt::Horizontal, tr("Part ID"));
model->setHeaderData(2, Qt::Horizontal, tr("Part Quantity"));
model->setHeaderData(3, Qt::Horizontal, tr("Part Name"));
model->setHeaderData(4, Qt::Horizontal, tr("Part Cost"));
if(model->query().isSelect()){
//the model is also used bellow at: on_tbl_Parts_Used_In_Service_doubleClicked()//
ui->tbl_Parts_Used_In_Service->setModel(model);
//Next 3 lines: Usefull info, but noise for the user, so we hide//
ui->tbl_Parts_Used_In_Service->hideColumn(0);
ui->tbl_Parts_Used_In_Service->hideColumn(1);
ui->tbl_Parts_Used_In_Service->hideColumn(2);
ui->tbl_Parts_Used_In_Service->resizeColumnsToContents();
//Sum the Parts Used Value and add//
double PartsCost = 0;
const int column = 4; //"Part_Cost column"//
for (int row = 0; row < model->rowCount(); ++row) {
PartsCost += model->data(model->index(row, column)).toDouble();
}
QSqlQuery SetServicePartsCost;
SetServicePartsCost.prepare("update Service set Service_Parts_Cost = :PartsCost WHERE Service_id = " + ServiceID);
SetServicePartsCost.bindValue(":PartsCost", PartsCost);
if (SetServicePartsCost.exec() == false){
QMessageBox::critical(this, tr("Error!"), SetServicePartsCost.lastError().text() + " class Client_Add_Service::LoadPartsAndServiceCostsGrid() ");
}
}
Add_Service_Description_Text();
Sum_Costs();
}
void Client_Add_Service::Sum_Costs()
{
QSqlQueryModel* model = new QSqlQueryModel;
model->setQuery("SELECT Service_Hours_Duration, Service_Parts_Cost, Service_Hour_Cost, Service_Paid, Service_Finished FROM Service WHERE Service_id = " + ServiceID);
double Amount_of_Hand_Work_Hours = model->data(model->index(0, 0)).toDouble(); //query result line 0 column 0 //worked hours
double Service_Parts_Cost = model->data(model->index(0, 1)).toDouble(); //query result line 0 column 1
double Service_Hour_Cost = model->data(model->index(0, 2)).toDouble(); //query result line 0 column 2 //hour cost in this service
ui->spin_double_Service_cost_per_hour->setValue(Service_Hour_Cost); //this Service cost per hour
ui->Spin_amount_of_Hand_Worked_Hours->setValue(Amount_of_Hand_Work_Hours); //amount of worked hours
ui->lcd_Service_HoursCost_total->display(Service_Hour_Cost * Amount_of_Hand_Work_Hours); //preice per hour in this service
ui->lcd_Service_Total->display((Amount_of_Hand_Work_Hours * Service_Hour_Cost) + Service_Parts_Cost);
ui->lcd_Parts_Cost->display(Service_Parts_Cost);
//Service_Paid CheckMark 0 for not Paid 1 for Paid
bool Service_Paid = model->data(model->index(0, 3)).toBool(); //query result line 0 column 3
if(Service_Paid){
ui->check_Paid->setChecked(true);
}else{
ui->check_Paid->setChecked(false);
}
//Service_Finished CheckMark 0 for not Finished 1 for Finished
bool Service_Finished = model->data(model->index(0, 4)).toBool(); //query result line 0 column 4
if(Service_Finished){
ui->check_Finished->setChecked(true);
}else{
ui->check_Finished->setChecked(false);
}
}
void Client_Add_Service::on_btn_Add_Parts_Used_In_The_Service_clicked()
{
Stock_Parts_Selection Stock_Parts_Selection;
Stock_Parts_Selection.setServiceID(ServiceID);
Stock_Parts_Selection.exec();
Load_Parts_And_Service_Costs_Grid();
}
void Client_Add_Service::on_tbl_Parts_Used_In_Service_doubleClicked(const QModelIndex &index)
{
if (QMessageBox::Yes == QMessageBox(QMessageBox::Information, tr("Confirmation!"), tr("Do you really want to remove this Part from the Service?"), QMessageBox::Yes|QMessageBox::No).exec())
{
//Bellow 2 list will retrieve the column 0 value, which is the ServicePartsUsed_id //
const QAbstractItemModel * model = index.model();
QVariant ServicePart_ID = model->data(model->index(index.row(), 0, index.parent()), Qt::DisplayRole);
//qDebug() << "ServicePartsUsed_id" << ServicePart_ID;
QSqlQuery removePartsFromService;
removePartsFromService.prepare("DELETE FROM ServicePartsUsed WHERE ServicePartsUsed_id = " + ServicePart_ID.toString());
//removePartsFromService.bindValue(":ServicePartsUsed_id", ServicePart_ID.toString());
removePartsFromService.exec();
//RETURN PART TO STOCK//
//Bellow 2 list will retrieve the column 0 value, which is the ServicePartsUsed_id //
const QAbstractItemModel * model2 = index.model();
QVariant partID = model2->data(model2->index(index.row(), 1, index.parent()), Qt::DisplayRole);
//qDebug() << "PartID" << partID;
QSqlQuery returnPartToStock;
returnPartToStock.prepare("UPDATE Part SET Part_Quantity = (Part_Quantity + 1) WHERE Part_id = :partID");
returnPartToStock.bindValue(":partID", partID.toString());
if(returnPartToStock.exec() == false){
QMessageBox::critical(this, tr("Error!"), returnPartToStock.lastError().text() + "class addservice.cpp on_btn_save_hoursWorked_clicked()");
}
Load_Parts_And_Service_Costs_Grid();
}
}
void Client_Add_Service::on_check_Paid_clicked()
{
if(ui->check_Paid->isChecked()){
QSqlQuery query;
query.prepare("UPDATE Service SET Service_Paid = 1 WHERE Service_Id = " + ServiceID);
if (query.exec() == false){
qDebug() << query.lastError();
QMessageBox::critical(this, tr("Error!"), query.lastError().text() + "class addservice.cpp on_check_Pago_clicked ");
}else{
QMessageBox::information(this, tr("Paid?!"), tr("Service switched to:\n Paid"));
}
}else{
QSqlQuery query;
query.prepare("UPDATE Service SET Service_Paid = 0 WHERE Service_Id = " + ServiceID);
if (query.exec() == false){
qDebug() << query.lastError();
QMessageBox::critical(this, tr("Error!"), query.lastError().text() + "class addservice.cpp on_check_Pago_clicked(not checked) ");
}else{
QMessageBox::information(this, tr("Paid?"), tr("Service switched to:\n Not Paid"));
}
}
}
void Client_Add_Service::on_check_Finished_clicked()
{
if(ui->check_Finished->isChecked()){
QSqlQuery query;
query.prepare("UPDATE Service SET Service_Finished = 1 WHERE Service_Id = " + ServiceID);
if (query.exec() == false){
qDebug() << query.lastError();
QMessageBox::critical(this, tr("Error!"), query.lastError().text() + "class addservice.cpp on_check_Finished_clicked ");
}else{
QMessageBox::information(this, tr("Finished?!"), tr("Service switched to:\nFinished"));
}
}else{
QSqlQuery query;
query.prepare("UPDATE Service SET Service_Finished = 0 WHERE Service_Id = " + ServiceID);
if (query.exec() == false){
qDebug() << query.lastError();
QMessageBox::critical(this, tr("Error!"), query.lastError().text() + "class addservice.cpp on_check_Finished_clicked() ");
}else{
QMessageBox::information(this, tr("Finished?"), tr("Service switched to:\nNot finished"));
}
}
}
void Client_Add_Service::on_btn_Update_Service_description_clicked()
{
Service_Update_Description service_Update_Description;
service_Update_Description.setServiceID(ServiceID);
service_Update_Description.Set_Description();
service_Update_Description.exec();
Add_Service_Description_Text();
}
void Client_Add_Service::on_btnBox_Close_rejected()
{
close();
}
//TODO :: Work In progress TODO//
void Client_Add_Service::on_dateTimeEdit_dateTimeChanged()
{
QSqlQuery query;
//query.prepare("UPDATE Service SET Service_Client_Will_Retrieve_At " + dateTime.toString("yyyy-MM-dd hh:mm:ss"));
if (query.exec() == false){
qDebug() << query.lastError();
QMessageBox::critical(this, tr("Error!"), query.lastError().text() + "class addservice.cpp on_check_Finished_clicked ");
}else{
QMessageBox::information(this, tr("TODO TODO TODO Ok!"), tr("Vehicle Retrieval Date Set..."));
}
}
void Client_Add_Service::on_Button_Apply_new_Hour_Cost_clicked()
{
QSqlQuery Update_Service_Cost;
Update_Service_Cost.prepare("UPDATE Service SET Service_Hour_Cost = :Service_Hour_Cost WHERE Service_id = " + ServiceID);
Update_Service_Cost.bindValue(":Service_Hour_Cost", ui->spin_double_Service_cost_per_hour->value());
if (!(Update_Service_Cost.exec())){
QMessageBox::critical(this, tr("Error!"), Update_Service_Cost.lastError().text() + "class Client_Add_Service::on_Button_Apply_new_Hour_Cost_clicked()");
}else{
QMessageBox::information(this, tr("Ok!"), tr("Service Hour Cost for this service updated..."));
Load_Parts_And_Service_Costs_Grid();
Sum_Costs();
}
}
void Client_Add_Service::LoadSettings()
{
QSettings setting("bedi1982","Oficina");
setting.beginGroup("Client_Add_Service");
QRect myrect = setting.value("position").toRect();
setGeometry(myrect);
setting.endGroup();
}
void Client_Add_Service::SaveSettings()
{
QSettings setting("bedi1982","Oficina");
setting.beginGroup("Client_Add_Service");
setting.setValue("position",this->geometry());
setting.endGroup();
}
void Client_Add_Service::on_buttonBox_Close_rejected()
{
close();
}
void Client_Add_Service::on_Button_Set_Worked_hours_clicked()
{
//if(ui->Spin_Hand_Work_Hours->valueChanged();
QSqlQuery Update_Hours_Worked;
Update_Hours_Worked.prepare("UPDATE Service SET Service_Hours_Duration = :Service_Hours_Duration WHERE Service_id = " + ServiceID);
Update_Hours_Worked.bindValue(":Service_Hours_Duration", ui->Spin_amount_of_Hand_Worked_Hours->value());
if (Update_Hours_Worked.exec()){
QMessageBox::information(this, tr("Done!!"), tr("Quantity of worked hoursgot an update!!"));
Sum_Costs();
}else{
QMessageBox::critical(this, tr("Error!"), Update_Hours_Worked.lastError().text() + "class Client_Add_Service::on_btn_save_hoursWorked_clicked()");
}
}