├── 786Plastics.pro
├── 786Plastics.pro.user
├── 786Plastics.pro.user.43dc162
├── 786Plastics.pro.user.b351d5d
├── 786Plastics.pro.user.cf060ee
├── 786Plastics.pro.user.f073dde
├── 786Plastics.pro.user.ff66615
├── README.md
├── Records
├── .gitkeep
└── database.db
├── application.cpp
├── application.h
├── buydialog.cpp
├── buydialog.h
├── buydialog.ui
├── dealermodel.cpp
├── dealermodel.h
├── factory.cpp
├── factory.h
├── factory.ui
├── img
├── .gitkeep
├── 20160528014858.jpg
├── Buy-48.png
├── Sell Stock-64.png
├── User-icon.png
├── back.jpg
├── cash-payment-icon-5.png
├── dealers_icon.jpg
├── diyarbakir-nakliyat.jpg
├── fork5.png
├── gconstruct1-06.png
├── grren_login_screen_by_h2o4life-d3181xz.png
├── home-content-dealer-icon.png
├── icon_suppliers.png
├── login_icon.png
├── main.png
├── payment-clipart-k9923905.jpg
├── sales-icon-large.png
├── supplier_icon.png
└── user-male-shape-in-a-circle--ios-7-interface-symbol_318-35357.png
├── logindialog.cpp
├── logindialog.h
├── logindialog.ui
├── main.cpp
├── paymentdialog.cpp
├── paymentdialog.h
├── paymentdialog.ui
├── paymentmodel.cpp
├── paymentmodel.h
├── reportsdialog.cpp
├── reportsdialog.h
├── reportsdialog.ui
├── resource.qrc
├── salesmodel.cpp
├── salesmodel.h
├── selldialog.cpp
├── selldialog.h
├── selldialog.ui
├── settingsdialog.cpp
├── settingsdialog.h
├── settingsdialog.ui
├── stockmodel.cpp
├── stockmodel.h
├── tableprinter.cpp
└── tableprinter.h
/786Plastics.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2016-07-23T22:37:11
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui sql charts printsupport
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = 786Plastics
12 | TEMPLATE = app
13 |
14 |
15 | SOURCES += main.cpp\
16 | factory.cpp \
17 | paymentdialog.cpp \
18 | selldialog.cpp \
19 | buydialog.cpp \
20 | logindialog.cpp \
21 | settingsdialog.cpp \
22 | dealermodel.cpp \
23 | stockmodel.cpp \
24 | salesmodel.cpp \
25 | paymentmodel.cpp \
26 | application.cpp \
27 | reportsdialog.cpp \
28 | tableprinter.cpp
29 |
30 | HEADERS += \
31 | factory.h \
32 | paymentdialog.h \
33 | selldialog.h \
34 | buydialog.h \
35 | logindialog.h \
36 | settingsdialog.h \
37 | dealermodel.h \
38 | stockmodel.h \
39 | salesmodel.h \
40 | paymentmodel.h \
41 | application.h \
42 | reportsdialog.h \
43 | tableprinter.h
44 |
45 | FORMS += \
46 | factory.ui \
47 | paymentdialog.ui \
48 | selldialog.ui \
49 | buydialog.ui \
50 | logindialog.ui \
51 | settingsdialog.ui \
52 | reportsdialog.ui
53 |
54 | RESOURCES += \
55 | resource.qrc
56 |
--------------------------------------------------------------------------------
/786Plastics.pro.user.b351d5d:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {b351d5df-f1d2-49d4-a3ac-c92671c74cc9}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 |
60 | ProjectExplorer.Project.Target.0
61 |
62 | Desktop Qt 5.7.0 MSVC2015_64bit
63 | Desktop Qt 5.7.0 MSVC2015_64bit
64 | qt.57.win64_msvc2015_64_kit
65 | 0
66 | 0
67 | 0
68 |
69 | C:/Users/Shahzaib/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug
70 |
71 |
72 | true
73 | qmake
74 |
75 | QtProjectManager.QMakeBuildStep
76 | true
77 |
78 | false
79 | false
80 | false
81 |
82 |
83 | true
84 | Make
85 |
86 | Qt4ProjectManager.MakeStep
87 |
88 | false
89 |
90 |
91 |
92 | 2
93 | Build
94 |
95 | ProjectExplorer.BuildSteps.Build
96 |
97 |
98 |
99 | true
100 | Make
101 |
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 |
108 | 1
109 | Clean
110 |
111 | ProjectExplorer.BuildSteps.Clean
112 |
113 | 2
114 | false
115 |
116 | Debug
117 |
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 | true
121 |
122 |
123 | C:/Users/Shahzaib/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_7_0_MSVC2015_64bit-Release
124 |
125 |
126 | true
127 | qmake
128 |
129 | QtProjectManager.QMakeBuildStep
130 | false
131 |
132 | false
133 | false
134 | false
135 |
136 |
137 | true
138 | Make
139 |
140 | Qt4ProjectManager.MakeStep
141 |
142 | false
143 |
144 |
145 |
146 | 2
147 | Build
148 |
149 | ProjectExplorer.BuildSteps.Build
150 |
151 |
152 |
153 | true
154 | Make
155 |
156 | Qt4ProjectManager.MakeStep
157 |
158 | true
159 | clean
160 |
161 |
162 | 1
163 | Clean
164 |
165 | ProjectExplorer.BuildSteps.Clean
166 |
167 | 2
168 | false
169 |
170 | Release
171 |
172 | Qt4ProjectManager.Qt4BuildConfiguration
173 | 0
174 | true
175 |
176 |
177 | C:/Users/Shahzaib/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_7_0_MSVC2015_64bit-Profile
178 |
179 |
180 | true
181 | qmake
182 |
183 | QtProjectManager.QMakeBuildStep
184 | true
185 |
186 | false
187 | true
188 | false
189 |
190 |
191 | true
192 | Make
193 |
194 | Qt4ProjectManager.MakeStep
195 |
196 | false
197 |
198 |
199 |
200 | 2
201 | Build
202 |
203 | ProjectExplorer.BuildSteps.Build
204 |
205 |
206 |
207 | true
208 | Make
209 |
210 | Qt4ProjectManager.MakeStep
211 |
212 | true
213 | clean
214 |
215 |
216 | 1
217 | Clean
218 |
219 | ProjectExplorer.BuildSteps.Clean
220 |
221 | 2
222 | false
223 |
224 | Profile
225 |
226 | Qt4ProjectManager.Qt4BuildConfiguration
227 | 0
228 | true
229 |
230 | 3
231 |
232 |
233 | 0
234 | Deploy
235 |
236 | ProjectExplorer.BuildSteps.Deploy
237 |
238 | 1
239 | Deploy locally
240 |
241 | ProjectExplorer.DefaultDeployConfiguration
242 |
243 | 1
244 |
245 |
246 | false
247 | false
248 | 1000
249 |
250 | true
251 |
252 | false
253 | false
254 | false
255 | false
256 | true
257 | 0.01
258 | 10
259 | true
260 | 1
261 | 25
262 |
263 | 1
264 | true
265 | false
266 | true
267 | valgrind
268 |
269 | 0
270 | 1
271 | 2
272 | 3
273 | 4
274 | 5
275 | 6
276 | 7
277 | 8
278 | 9
279 | 10
280 | 11
281 | 12
282 | 13
283 | 14
284 |
285 | 2
286 |
287 | 786Plastics
288 |
289 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Shahzaib/Documents/QT Projects/786Plastics/786Plastics.pro
290 | true
291 |
292 | 786Plastics.pro
293 | false
294 |
295 | C:/Users/Shahzaib/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug
296 | 3768
297 | false
298 | true
299 | false
300 | false
301 | true
302 |
303 | 1
304 |
305 |
306 |
307 | ProjectExplorer.Project.TargetCount
308 | 1
309 |
310 |
311 | ProjectExplorer.Project.Updater.FileVersion
312 | 18
313 |
314 |
315 | Version
316 | 18
317 |
318 |
319 |
--------------------------------------------------------------------------------
/786Plastics.pro.user.f073dde:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {f073dde6-9ff4-4efe-9614-ad591ca6a2ae}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | 0
45 | 8
46 | true
47 | 1
48 | true
49 | true
50 | true
51 | false
52 |
53 |
54 |
55 | ProjectExplorer.Project.PluginSettings
56 |
57 |
58 |
59 | ProjectExplorer.Project.Target.0
60 |
61 | Desktop Qt 5.6.0 MSVC2015 64bit
62 | Desktop Qt 5.6.0 MSVC2015 64bit
63 | qt.56.win64_msvc2015_64_kit
64 | 1
65 | 0
66 | 0
67 |
68 | C:/Users/Sehar/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_6_0_MSVC2015_64bit-Debug
69 |
70 |
71 | true
72 | qmake
73 |
74 | QtProjectManager.QMakeBuildStep
75 | true
76 |
77 | false
78 | false
79 | false
80 |
81 |
82 | true
83 | Make
84 |
85 | Qt4ProjectManager.MakeStep
86 |
87 | false
88 |
89 |
90 |
91 | 2
92 | Build
93 |
94 | ProjectExplorer.BuildSteps.Build
95 |
96 |
97 |
98 | true
99 | Make
100 |
101 | Qt4ProjectManager.MakeStep
102 |
103 | true
104 | clean
105 |
106 |
107 | 1
108 | Clean
109 |
110 | ProjectExplorer.BuildSteps.Clean
111 |
112 | 2
113 | false
114 |
115 | Debug
116 |
117 | Qt4ProjectManager.Qt4BuildConfiguration
118 | 2
119 | true
120 |
121 |
122 | C:/Users/Sehar/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_6_0_MSVC2015_64bit-Release
123 |
124 |
125 | true
126 | qmake
127 |
128 | QtProjectManager.QMakeBuildStep
129 | false
130 |
131 | false
132 | false
133 | false
134 |
135 |
136 | true
137 | Make
138 |
139 | Qt4ProjectManager.MakeStep
140 |
141 | false
142 |
143 |
144 |
145 | 2
146 | Build
147 |
148 | ProjectExplorer.BuildSteps.Build
149 |
150 |
151 |
152 | true
153 | Make
154 |
155 | Qt4ProjectManager.MakeStep
156 |
157 | true
158 | clean
159 |
160 |
161 | 1
162 | Clean
163 |
164 | ProjectExplorer.BuildSteps.Clean
165 |
166 | 2
167 | false
168 |
169 | Release
170 |
171 | Qt4ProjectManager.Qt4BuildConfiguration
172 | 0
173 | true
174 |
175 |
176 | C:/Users/Sehar/Documents/QT Projects/build-786Plastics-Desktop_Qt_5_6_0_MSVC2015_64bit-Profile
177 |
178 |
179 | true
180 | qmake
181 |
182 | QtProjectManager.QMakeBuildStep
183 | true
184 |
185 | false
186 | true
187 | false
188 |
189 |
190 | true
191 | Make
192 |
193 | Qt4ProjectManager.MakeStep
194 |
195 | false
196 |
197 |
198 |
199 | 2
200 | Build
201 |
202 | ProjectExplorer.BuildSteps.Build
203 |
204 |
205 |
206 | true
207 | Make
208 |
209 | Qt4ProjectManager.MakeStep
210 |
211 | true
212 | clean
213 |
214 |
215 | 1
216 | Clean
217 |
218 | ProjectExplorer.BuildSteps.Clean
219 |
220 | 2
221 | false
222 |
223 | Profile
224 |
225 | Qt4ProjectManager.Qt4BuildConfiguration
226 | 0
227 | true
228 |
229 | 3
230 |
231 |
232 | 0
233 | Deploy
234 |
235 | ProjectExplorer.BuildSteps.Deploy
236 |
237 | 1
238 | Deploy locally
239 |
240 | ProjectExplorer.DefaultDeployConfiguration
241 |
242 | 1
243 |
244 |
245 | false
246 | 1000
247 |
248 | true
249 |
250 | false
251 | false
252 | false
253 | false
254 | true
255 | 0.01
256 | 10
257 | true
258 | 1
259 | 25
260 |
261 | 1
262 | true
263 | false
264 | true
265 | valgrind
266 |
267 | 0
268 | 1
269 | 2
270 | 3
271 | 4
272 | 5
273 | 6
274 | 7
275 | 8
276 | 9
277 | 10
278 | 11
279 | 12
280 | 13
281 | 14
282 |
283 | 2
284 |
285 | 786Plastics
286 |
287 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Sehar/Documents/QT Projects/786Plastics/786Plastics.pro
288 | true
289 |
290 | 786Plastics.pro
291 | false
292 | false
293 |
294 | 3768
295 | false
296 | true
297 | false
298 | false
299 | true
300 |
301 | 1
302 |
303 |
304 |
305 | ProjectExplorer.Project.TargetCount
306 | 1
307 |
308 |
309 | ProjectExplorer.Project.Updater.FileVersion
310 | 18
311 |
312 |
313 | Version
314 | 18
315 |
316 |
317 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/README.md
--------------------------------------------------------------------------------
/Records/.gitkeep:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Records/database.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/Records/database.db
--------------------------------------------------------------------------------
/application.cpp:
--------------------------------------------------------------------------------
1 | #include "application.h"
2 |
3 | Application::Application(int& argc, char** argv) :
4 | QApplication(argc, argv)
5 | {
6 | m_dontShowMainWindow = true;
7 | // Set organisation and application names
8 | setApplicationName("786Plastics");
9 | setApplicationVersion("3.00");
10 | setOrganizationName("Shaprianz");
11 | setApplicationDisplayName("786Plastics");
12 | setWindowIcon(QIcon(":/images/img/main.png"));
13 |
14 |
15 | // Show login dialog
16 | login = new LoginDialog();
17 | login->show();
18 | login->setAttribute(Qt::WA_DeleteOnClose);
19 | if(login != Q_NULLPTR)
20 | m_dontShowMainWindow = false;
21 |
22 | connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
23 | }
24 |
25 | Application::~Application()
26 | {
27 | delete login;
28 | }
29 |
--------------------------------------------------------------------------------
/application.h:
--------------------------------------------------------------------------------
1 | #ifndef APPLICATION_H
2 | #define APPLICATION_H
3 |
4 | #include
5 | #include "logindialog.h"
6 | #include
7 |
8 |
9 | class Application : public QApplication
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | explicit Application(int& argc, char** argv);
15 | virtual ~Application();
16 |
17 | bool dontShowMainWindow() { return m_dontShowMainWindow; }
18 |
19 | private:
20 | bool m_dontShowMainWindow;
21 | LoginDialog *login;
22 | };
23 |
24 |
25 | #endif // APPLICATION_H
26 |
--------------------------------------------------------------------------------
/buydialog.cpp:
--------------------------------------------------------------------------------
1 | #include "buydialog.h"
2 | #include "ui_buydialog.h"
3 | #include
4 | #include
5 |
6 | BuyDialog::BuyDialog(QString supplier, QSqlDatabase *database,
7 | QSqlQueryModel *model, QWidget *parent) :
8 | db(database),
9 | QDialog(parent),
10 | net_weight(0),
11 | total_price(0),
12 | ui(new Ui::BuyDialog)
13 | {
14 | ui->setupUi(this);
15 | ui->dateEdit->setDate(QDate::currentDate());
16 | ui->price_spinbox->installEventFilter(this);
17 |
18 |
19 | //check database
20 | if(!db->open()){
21 | QMessageBox::critical(this,"Database","The database couldn't"
22 | "be connected.");
23 | ui->status_label->setText("Database not connected");
24 | }else
25 | ui->status_label->setText("Database connected");
26 |
27 | //update model
28 | setupModels(model);
29 | ui->supplier_edit->setText(supplier);
30 | ui->sr_spinbox->setFocus();
31 |
32 | }
33 |
34 | void BuyDialog::setupModels(QSqlQueryModel *model)
35 | {
36 | Q_UNUSED(model);
37 | //setup combo boxes and list view
38 | setupMaterialModel();
39 | }
40 |
41 | void BuyDialog::setupMaterialModel()
42 | {
43 | material_model = new QSqlQueryModel(this);
44 | QSqlQuery q(*db);
45 | QString query = "select type from raw_materials order by type";
46 |
47 | if(!q.exec(query)){
48 | QSqlError err = q.lastError();
49 | QMessageBox::critical(this,"Error",err.text());
50 | }
51 | material_model->setQuery(q);
52 |
53 | //set models of views
54 | ui->material_combo->setModel(material_model);
55 | ui->material_view->setModel(material_model);
56 |
57 | //set to the first element
58 | ui->material_combo->setCurrentIndex(0);
59 | }
60 |
61 | void BuyDialog::displayTotals()
62 | {
63 | ui->netweight_spinbox->setValue(net_weight);
64 | ui->totalprice_spinbox->setValue(total_price);
65 | }
66 |
67 | void BuyDialog::showDetailString()
68 | {
69 | QString material = ui->material_combo->currentText();
70 | QString weight = QString::number(ui->weight_spinbox->value());
71 | QString price = QString::number(ui->price_spinbox->value());
72 |
73 | QString supply = ""
74 | +material+"
"
75 | +weight +" kg | "+price+" Rs
";
76 | //set the text edit
77 | QString old_text = ui->detail_text->toHtml();
78 | QString new_text = old_text+"
"+supply;
79 | ui->detail_text->setText(new_text);
80 | }
81 |
82 | bool BuyDialog::buySupply()
83 | {
84 | QString serial_no = QString::number(ui->sr_spinbox->value());
85 | QString supplier = ui->supplier_edit->text();
86 | qint64 netWeight = ui->netweight_spinbox->value();
87 | qint64 price = ui->totalprice_spinbox->value();
88 | QString detail = ui->detail_text->toHtml();
89 | qint64 paid = ui->cashpaid_spinbox->value();
90 | QString date = ui->dateEdit->date().toString("yyyy-MM-dd");
91 |
92 | //calculate remaining cash
93 | qint64 remaining;
94 | if(price!=paid)
95 | remaining = price - paid;
96 | //prepare the query
97 | QSqlQuery q(*db);
98 | q.prepare("insert into supplies (serial,supplier,net_weight,price"
99 | ",detail,paid,date) values (?,?,?,?,?,?,?)");
100 | q.bindValue(0,serial_no);
101 | q.bindValue(1,supplier);
102 | q.bindValue(2,netWeight);
103 | q.bindValue(3,price);
104 | q.bindValue(4,detail);
105 | q.bindValue(5,paid);
106 | q.bindValue(6,date);
107 | //execute the query
108 | if(!q.exec()){
109 | QSqlError err = q.lastError();
110 | QMessageBox::critical(this,"Error","Couldn't add supply info"
111 | "to the database\n"+err.text());
112 | return false;
113 | }else{
114 | //now add the remaining amount to the suppliers balance
115 | if(!updateSupplierBalance(supplier,remaining))
116 | return false;
117 | }
118 | return true;
119 | }
120 |
121 | bool BuyDialog::updateSupplierBalance(QString supplier, qint64 remaining)
122 | {
123 | QSqlQuery q(*db);
124 | q.prepare("update supplier set balance =balance+? where name=?");
125 | q.bindValue(0,remaining);
126 | q.bindValue(1,supplier);
127 | //execute the query
128 | if(!q.exec()){
129 | QSqlError err = q.lastError();
130 | QMessageBox::critical(this,"Error","Couldn't update supplier"
131 | " balance"
132 | "due to "+err.text());
133 | return false;
134 | }else{
135 | QMessageBox::information(this,"Amount Added to "+supplier+"'s account.","Successfull");
136 | return true;
137 | }
138 | }
139 |
140 | bool BuyDialog::areFieldsEmpty()
141 | {
142 | if(ui->weight_spinbox->value() == 0 ||
143 | ui->price_spinbox->value() == 0)
144 | return true;
145 | return false;
146 | }
147 |
148 | BuyDialog::~BuyDialog()
149 | {
150 | delete material_model;
151 | delete ui;
152 | }
153 |
154 | bool BuyDialog::eventFilter(QObject *watched, QEvent *event)
155 | {
156 | if(watched==ui->price_spinbox && event->type()==QEvent::KeyPress){
157 | QKeyEvent *keyEvent = static_cast(event);
158 | if(keyEvent->key()==Qt::Key_Return ||
159 | keyEvent->key()==Qt::Key_Enter){
160 | if(ui->next_toolbutton->isEnabled())
161 | on_next_toolbutton_clicked();
162 | }
163 | }
164 | return QDialog::eventFilter(watched,event);
165 | }
166 |
167 |
168 | /// private slots
169 |
170 | void BuyDialog::on_next_toolbutton_clicked()
171 | {
172 | //check if the fields are empty
173 | if(areFieldsEmpty()){
174 | qDebug() << "Fields empty";
175 | return;
176 | }
177 |
178 | //add to the total
179 | qint64 weight = ui->weight_spinbox->value();
180 | qint64 price = ui->calculatedprice_spinbox->value();
181 | total_price += price;
182 | net_weight += weight;
183 | displayTotals();
184 | //prepare the supply detail string
185 | showDetailString();
186 | //select the next material in combo box
187 | int count = ui->material_combo->count();
188 | int currentIndex = ui->material_combo->currentIndex();
189 |
190 | if(currentIndex!=(count-1)){
191 | ui->material_combo->setCurrentIndex(currentIndex+1);
192 | ui->weight_spinbox->setFocus();
193 | }
194 |
195 | //clear the fields
196 | ui->price_spinbox->clear();
197 | ui->weight_spinbox->clear();
198 | ui->next_toolbutton->setEnabled(false);
199 | }
200 |
201 |
202 | void BuyDialog::on_reset_button_clicked()
203 | {
204 | net_weight = 0;
205 | total_price = 0;
206 | ui->weight_spinbox->clear();
207 | ui->price_spinbox->clear();
208 | ui->detail_text->clear();
209 | displayTotals();
210 | }
211 |
212 | void BuyDialog::on_recievesupply_button_clicked()
213 | {
214 | //confirms from the user
215 | QMessageBox::StandardButton reply;
216 | reply = QMessageBox::question(this,"Are You Sure?",
217 | "You can not undo the entry."
218 | "Do you want to continue?",
219 | QMessageBox::Yes | QMessageBox::Cancel);
220 | //if the user accepts the dialog
221 | if(reply==QMessageBox::Yes){
222 | //begin the transaction
223 | db->transaction();
224 | transacting = true;
225 | //buy process started
226 | if(!buySupply()){
227 | QMessageBox::warning(this,"Failed","Failed to buy supply.try again!");
228 | db->rollback();
229 | transacting = false;
230 | return;
231 | }
232 | //if everything goes well
233 | db->commit();
234 | transacting = false;
235 | accept();
236 | }
237 |
238 | }
239 |
240 | void BuyDialog::on_weight_spinbox_valueChanged(int arg1)
241 | {
242 | if(!(ui->weight_spinbox->value()<=0 ||
243 | ui->price_spinbox->value()<=0))
244 | ui->next_toolbutton->setEnabled(true);
245 | else
246 | ui->next_toolbutton->setEnabled(false);
247 |
248 | //calculate total price
249 | qint64 total = arg1*ui->price_spinbox->value();
250 | ui->calculatedprice_spinbox->setValue(total);
251 | }
252 |
253 | void BuyDialog::on_price_spinbox_valueChanged(int arg1)
254 | {
255 | on_weight_spinbox_valueChanged(arg1);
256 | //calculate total price
257 | qint64 total = arg1*ui->weight_spinbox->value();
258 | ui->calculatedprice_spinbox->setValue(total);
259 | }
260 |
261 |
--------------------------------------------------------------------------------
/buydialog.h:
--------------------------------------------------------------------------------
1 | #ifndef BUYDIALOG_H
2 | #define BUYDIALOG_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | namespace Ui {
10 | class BuyDialog;
11 | }
12 |
13 | class BuyDialog : public QDialog
14 | {
15 | Q_OBJECT
16 | public:
17 | explicit BuyDialog(QString supplier,QSqlDatabase *database,
18 | QSqlQueryModel *model,QWidget *parent = 0);
19 |
20 | void setupModels(QSqlQueryModel *model);
21 | void setupMaterialModel();
22 | void displayTotals(); //set the total values in line edits
23 | void showDetailString(); //creates the detatiled string of supply items
24 | bool buySupply(); //implements the buying logic of database
25 | bool updateSupplierBalance(QString supplier,qint64 remaining); //adds the remaining amount to the suppliers account
26 | bool areFieldsEmpty();
27 |
28 | ~BuyDialog();
29 |
30 | protected:
31 | bool eventFilter(QObject *watched, QEvent *event);
32 |
33 | private slots:
34 | void on_next_toolbutton_clicked();
35 | void on_reset_button_clicked();
36 | void on_recievesupply_button_clicked();
37 | void on_weight_spinbox_valueChanged(int arg1);
38 | void on_price_spinbox_valueChanged(int arg1);
39 |
40 | private:
41 | Ui::BuyDialog *ui;
42 | QSqlDatabase *db;
43 | QSqlQueryModel *material_model;
44 | qint64 net_weight;
45 | qint64 total_price;
46 | bool transacting =false;
47 | };
48 |
49 | #endif // BUYDIALOG_H
50 |
--------------------------------------------------------------------------------
/buydialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | BuyDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 816
10 | 542
11 |
12 |
13 |
14 | Buy
15 |
16 |
17 | -
18 |
19 |
-
20 |
21 |
-
22 |
23 |
-
24 |
25 |
26 |
27 | 12
28 | 75
29 | true
30 |
31 |
32 |
33 | Date
34 |
35 |
36 |
37 | -
38 |
39 |
40 |
41 | 12
42 | 75
43 | true
44 |
45 |
46 |
47 | sr#
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 | 12
56 | 75
57 | true
58 |
59 |
60 |
61 | Seller
62 |
63 |
64 |
65 | -
66 |
67 |
68 |
69 | 12
70 | 75
71 | true
72 |
73 |
74 |
75 | Material
76 |
77 |
78 | material_combo
79 |
80 |
81 |
82 | -
83 |
84 |
85 |
86 | 12
87 | 75
88 | true
89 |
90 |
91 |
92 | Weight
93 |
94 |
95 |
96 | -
97 |
98 |
99 |
100 | 12
101 | 75
102 | true
103 |
104 |
105 |
106 | Price/kg
107 |
108 |
109 |
110 |
111 |
112 | -
113 |
114 |
-
115 |
116 |
117 | background-color: rgb(255, 255, 255);
118 | font: 87 14pt "Segoe UI Black";
119 | color: rgb(234, 67, 53);
120 |
121 |
122 | dd-MMM
123 |
124 |
125 |
126 | -
127 |
128 |
129 |
130 | 12
131 | 75
132 | true
133 |
134 |
135 |
136 | background-color: rgb(64, 66, 68);
137 | color: rgb(176, 91, 1);
138 |
139 |
140 | 99999999
141 |
142 |
143 |
144 | -
145 |
146 |
147 | false
148 |
149 |
150 |
151 | 16
152 | 75
153 | true
154 |
155 |
156 |
157 | background-color: rgb(64, 66, 68);
158 | color: rgb(146, 189, 108);
159 |
160 |
161 |
162 | -
163 |
164 |
165 |
166 | 16
167 | 75
168 | true
169 |
170 |
171 |
172 |
173 | -
174 |
175 |
176 |
177 | 16
178 | 75
179 | true
180 |
181 |
182 |
183 | 99999999
184 |
185 |
186 |
187 | -
188 |
189 |
-
190 |
191 |
192 | false
193 |
194 |
195 | ->
196 |
197 |
198 |
199 | -
200 |
201 |
202 |
203 | 16
204 | 75
205 | true
206 |
207 |
208 |
209 | 99999999
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 | -
218 |
219 |
220 | false
221 |
222 |
223 |
224 | 20
225 | 75
226 | true
227 |
228 |
229 |
230 | 99999999
231 |
232 |
233 |
234 | -
235 |
236 |
237 |
238 | 12
239 | 75
240 | true
241 |
242 |
243 |
244 | Total Price
245 |
246 |
247 |
248 |
249 |
250 | -
251 |
252 |
-
253 |
254 |
-
255 |
256 |
257 |
258 | Ubuntu
259 | 16
260 | true
261 |
262 |
263 |
264 |
265 | -
266 |
267 |
268 | false
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 | 0
277 | 0
278 | 0
279 |
280 |
281 |
282 |
283 |
284 |
285 | 227
286 | 227
287 | 227
288 |
289 |
290 |
291 |
292 |
293 |
294 | 0
295 | 0
296 | 0
297 |
298 |
299 |
300 |
301 |
302 |
303 | 0
304 | 0
305 | 0
306 |
307 |
308 |
309 |
310 |
311 |
312 | 255
313 | 255
314 | 255
315 |
316 |
317 |
318 |
319 |
320 |
321 | 105
322 | 105
323 | 105
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 | 0
333 | 0
334 | 0
335 |
336 |
337 |
338 |
339 |
340 |
341 | 227
342 | 227
343 | 227
344 |
345 |
346 |
347 |
348 |
349 |
350 | 0
351 | 0
352 | 0
353 |
354 |
355 |
356 |
357 |
358 |
359 | 0
360 | 0
361 | 0
362 |
363 |
364 |
365 |
366 |
367 |
368 | 255
369 | 255
370 | 255
371 |
372 |
373 |
374 |
375 |
376 |
377 | 105
378 | 105
379 | 105
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 | 0
389 | 0
390 | 0
391 |
392 |
393 |
394 |
395 |
396 |
397 | 227
398 | 227
399 | 227
400 |
401 |
402 |
403 |
404 |
405 |
406 | 0
407 | 0
408 | 0
409 |
410 |
411 |
412 |
413 |
414 |
415 | 0
416 | 0
417 | 0
418 |
419 |
420 |
421 |
422 |
423 |
424 | 255
425 | 255
426 | 255
427 |
428 |
429 |
430 |
431 |
432 |
433 | 105
434 | 105
435 | 105
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 | color: rgb(0, 0, 0);
444 | font: 75 12pt "MS Shell Dlg 2";
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 | -
455 |
456 |
-
457 |
458 |
-
459 |
460 |
-
461 |
462 |
463 |
464 | 12
465 | 75
466 | true
467 |
468 |
469 |
470 | Net Weight
471 |
472 |
473 |
474 | -
475 |
476 |
477 |
478 | 12
479 | 75
480 | true
481 |
482 |
483 |
484 | Net Price
485 |
486 |
487 |
488 |
489 |
490 | -
491 |
492 |
-
493 |
494 |
495 | false
496 |
497 |
498 |
499 | 20
500 | 75
501 | true
502 |
503 |
504 |
505 | background-color: rgb(0, 0, 0);
506 | color: rgb(186, 96, 0);
507 |
508 |
509 | 99999999
510 |
511 |
512 |
513 | -
514 |
515 |
516 | false
517 |
518 |
519 |
520 | 20
521 | 75
522 | true
523 |
524 |
525 |
526 | background-color: rgb(0, 0, 0);
527 | color: rgb(146, 189, 108);
528 |
529 |
530 | 99999999
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 | -
539 |
540 |
-
541 |
542 |
-
543 |
544 |
545 |
546 | 12
547 | 75
548 | true
549 |
550 |
551 |
552 | Cash Paid
553 |
554 |
555 |
556 | -
557 |
558 |
559 | true
560 |
561 |
562 |
563 | 20
564 | 75
565 | true
566 |
567 |
568 |
569 | 0
570 |
571 |
572 |
573 |
574 |
575 | -
576 |
577 |
578 |
579 | 16
580 | 75
581 | true
582 |
583 |
584 |
585 | Recieve Supply
586 |
587 |
588 | Ctrl+R
589 |
590 |
591 | false
592 |
593 |
594 |
595 |
596 |
597 | -
598 |
599 |
-
600 |
601 |
-
602 |
603 |
604 | Reset
605 |
606 |
607 | Del
608 |
609 |
610 | false
611 |
612 |
613 |
614 | -
615 |
616 |
617 | Qt::Horizontal
618 |
619 |
620 |
621 | 40
622 | 20
623 |
624 |
625 |
626 |
627 |
628 |
629 | -
630 |
631 |
632 | Qt::Vertical
633 |
634 |
635 |
636 | 234
637 | 32
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 | -
647 |
648 |
649 | color: rgb(255, 0, 0);
650 |
651 |
652 | (+) status
653 |
654 |
655 |
656 |
657 |
658 |
659 | sr_spinbox
660 | material_combo
661 | weight_spinbox
662 | price_spinbox
663 | next_toolbutton
664 | cashpaid_spinbox
665 | recievesupply_button
666 | reset_button
667 | supplier_edit
668 | calculatedprice_spinbox
669 | netweight_spinbox
670 | totalprice_spinbox
671 | detail_text
672 | dateEdit
673 |
674 |
675 |
676 |
677 |
--------------------------------------------------------------------------------
/dealermodel.cpp:
--------------------------------------------------------------------------------
1 | #include "dealermodel.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | DealerModel::DealerModel(QObject *parent, short namecolumn,
8 | short balancecoulumn) :
9 | QSqlQueryModel(parent),
10 | _namecol(namecolumn),
11 | _balancecol(balancecoulumn)
12 | {
13 |
14 | }
15 |
16 | QVariant DealerModel::data(const QModelIndex &index, int role) const
17 | {
18 | if(index.isValid() && index.column()==_namecol
19 | && role==Qt::ForegroundRole){
20 | QColor text;
21 | text.setNamedColor("#3f9fd1");
22 | return QBrush(text);
23 | }
24 | if(index.isValid() && index.column()==_balancecol
25 | && role==Qt::ForegroundRole){
26 | QColor text;
27 | text.setNamedColor("#ba6000");
28 | return QBrush(text);
29 | }
30 | //font
31 | if(index.isValid() && role==Qt::FontRole){
32 | return QFont("times",12,QFont::DemiBold);
33 | }
34 | return QSqlQueryModel::data(index,role);
35 | }
36 |
37 | short DealerModel::balancecol() const
38 | {
39 | return _balancecol;
40 | }
41 |
42 | void DealerModel::setBalancecol(short balancecol)
43 | {
44 | _balancecol = balancecol;
45 | }
46 |
47 | short DealerModel::namecol() const
48 | {
49 | return _namecol;
50 | }
51 |
52 | void DealerModel::setNamecol(short namecol)
53 | {
54 | _namecol = namecol;
55 | }
56 |
--------------------------------------------------------------------------------
/dealermodel.h:
--------------------------------------------------------------------------------
1 | #ifndef DEALERMODEL_H
2 | #define DEALERMODEL_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | class DealerModel : public QSqlQueryModel
9 | {
10 | Q_OBJECT
11 | public:
12 | explicit DealerModel(QObject *parent,short namecolumn=0,
13 | short balancecoulumn=1);
14 |
15 | short namecol() const;
16 | void setNamecol(short namecol);
17 |
18 | short balancecol() const;
19 | void setBalancecol(short balancecol);
20 |
21 | protected:
22 | QVariant data(const QModelIndex &item, int role) const;
23 |
24 | private:
25 | short _namecol;
26 | short _balancecol;
27 | };
28 |
29 | #endif // DEALERMODEL_H
30 |
--------------------------------------------------------------------------------
/factory.h:
--------------------------------------------------------------------------------
1 | #ifndef FACTORY_H
2 | #define FACTORY_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "dealermodel.h"
10 | #include "stockmodel.h"
11 | #include "salesmodel.h"
12 | #include "paymentmodel.h"
13 |
14 | namespace Ui {
15 | class Factory;
16 | }
17 |
18 | class Factory : public QMainWindow
19 | {
20 | Q_OBJECT
21 |
22 | public:
23 | explicit Factory(QString user,QSqlDatabase *database,QWidget *parent = 0);
24 |
25 | void initializeModels();
26 | void setupModels();
27 | void setupDealersTabModel();
28 | void setupSuppliersTabModel();
29 | void setupPaymentTabModel();
30 | void setupDealsTabModel();
31 | void setupStocksTabModel();
32 | void setupTotalStockTabModel();
33 | void setupSuppliesTabModel();
34 | void setupStockShiftComboBoxModel();
35 | void setupStockEmployeeComboBoxModel();
36 | void setupMaterialsModel();
37 | bool addStockShift(); //adds the details to stocks table
38 | bool showSupplyDetail(QString serial);
39 |
40 | ~Factory();
41 |
42 | private slots:
43 |
44 | void on_dealersearch_edit_textChanged(const QString &arg1);
45 | void on_suppliersearch_edit_textChanged(const QString &arg1);
46 | void on_dealsearch_edit_textChanged(const QString &arg1);
47 | void on_TabView_tabBarClicked(int index);
48 | void on_action_Sell_triggered();
49 | void on_action_Buy_triggered();
50 | void on_actionRecieve_Payment_triggered();
51 | void on_newdealername_edit_textChanged(const QString &arg1);
52 | void on_adddealer_button_clicked();
53 | void on_newsuppliername_edit_textChanged(const QString &arg1);
54 | void on_addsupplier_button_clicked();
55 | void on_supplysearch_edit_textChanged(const QString &arg1);
56 | void on_actionOpen_Settings_triggered();
57 |
58 | void on_stockview_dateedit_userDateChanged(const QDate &date);
59 |
60 | void on_addstockshift_button_clicked();
61 |
62 | void on_dealers_tableview_doubleClicked(const QModelIndex &index);
63 |
64 | void on_suppliers_tableview_doubleClicked(const QModelIndex &index);
65 |
66 | void on_calendarWidget_clicked(const QDate &date);
67 |
68 | void on_pushButton_clicked();
69 | void on_dealsdatesearch_dateEdit_dateChanged(const QDate &date);
70 |
71 | void on_supplyserialsearch_edit_textChanged(const QString &arg1);
72 |
73 |
74 | void on_paymentdatesearch_dateEdit_dateChanged(const QDate &date);
75 |
76 | void on_paymentsdealersearch_lineEdit_textChanged(const QString &arg1);
77 |
78 | void on_generatereport_pushButton_clicked();
79 |
80 | void on_actionPay_Bills_triggered();
81 |
82 | void on_supplies_view_doubleClicked(const QModelIndex &index);
83 |
84 | void on_actionAbout_triggered();
85 |
86 | void on_suppliesdatesearch_dateEdit_dateChanged(const QDate &date);
87 |
88 | void on_actionReports_triggered();
89 |
90 | private:
91 | Ui::Factory *ui;
92 | QString username;
93 | QSqlDatabase *db;
94 | //filters
95 | QSortFilterProxyModel *dealer_proxy_model;
96 | QSortFilterProxyModel *deals_proxy_model;
97 | QSortFilterProxyModel *supplier_proxy_model;
98 | QSortFilterProxyModel *supply_proxy_model;
99 | QSortFilterProxyModel *payments_proxy_model;
100 | //models
101 | DealerModel *dealers_model;
102 | SalesModel *deals_model;
103 | PaymentModel *payment_model;
104 | DealerModel *supplier_model;
105 | SalesModel *supply_model;
106 | QSqlQueryModel *stocks_model;
107 | QSqlQueryModel *materials_model;
108 | QStringListModel *stockshift_model;
109 | QSqlQueryModel *machineman_model;
110 | StockModel *total_stock_model;
111 |
112 | bool transacting = false;
113 |
114 | };
115 |
116 | #endif // FACTORY_H
117 |
--------------------------------------------------------------------------------
/img/.gitkeep:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/img/20160528014858.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/20160528014858.jpg
--------------------------------------------------------------------------------
/img/Buy-48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/Buy-48.png
--------------------------------------------------------------------------------
/img/Sell Stock-64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/Sell Stock-64.png
--------------------------------------------------------------------------------
/img/User-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/User-icon.png
--------------------------------------------------------------------------------
/img/back.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/back.jpg
--------------------------------------------------------------------------------
/img/cash-payment-icon-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/cash-payment-icon-5.png
--------------------------------------------------------------------------------
/img/dealers_icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/dealers_icon.jpg
--------------------------------------------------------------------------------
/img/diyarbakir-nakliyat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/diyarbakir-nakliyat.jpg
--------------------------------------------------------------------------------
/img/fork5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/fork5.png
--------------------------------------------------------------------------------
/img/gconstruct1-06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/gconstruct1-06.png
--------------------------------------------------------------------------------
/img/grren_login_screen_by_h2o4life-d3181xz.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/grren_login_screen_by_h2o4life-d3181xz.png
--------------------------------------------------------------------------------
/img/home-content-dealer-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/home-content-dealer-icon.png
--------------------------------------------------------------------------------
/img/icon_suppliers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/icon_suppliers.png
--------------------------------------------------------------------------------
/img/login_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/login_icon.png
--------------------------------------------------------------------------------
/img/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/main.png
--------------------------------------------------------------------------------
/img/payment-clipart-k9923905.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/payment-clipart-k9923905.jpg
--------------------------------------------------------------------------------
/img/sales-icon-large.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/sales-icon-large.png
--------------------------------------------------------------------------------
/img/supplier_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/supplier_icon.png
--------------------------------------------------------------------------------
/img/user-male-shape-in-a-circle--ios-7-interface-symbol_318-35357.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZeroCoolHacker/FactoryManagment/376acf046ae16fea5fe770f3a611cd484cd31227/img/user-male-shape-in-a-circle--ios-7-interface-symbol_318-35357.png
--------------------------------------------------------------------------------
/logindialog.cpp:
--------------------------------------------------------------------------------
1 | #include "logindialog.h"
2 | #include "ui_logindialog.h"
3 | #include "factory.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | LoginDialog::LoginDialog(QWidget *parent) :
10 | QDialog(parent),
11 | ui(new Ui::LoginDialog)
12 | {
13 | ui->setupUi(this);
14 |
15 | // if(checkLicence())
16 | setupConnection();
17 | }
18 |
19 | bool LoginDialog::checkLicence()
20 | {
21 | QString filepath = "C:/Windows/shaprianz.spz";
22 | QFile file(filepath);
23 | if(!file.exists()){
24 | QMessageBox::information(this,"Caution!",
25 | "You are using this application "
26 | "without buying it.We can sue for "
27 | "5 lac rupees.Kindly contact the "
28 | "developer at 03316296093 to get "
29 | "your own software.");
30 | return false;
31 | }
32 | return true;
33 | }
34 |
35 | void LoginDialog::setupConnection()
36 | {
37 | db = QSqlDatabase::addDatabase("QSQLITE");
38 | QString path = qApp->applicationDirPath()+"/Records/database.db";
39 | QFile dbFile(path);
40 | if(!dbFile.exists()){
41 | QMessageBox::StandardButton reply;
42 | reply = QMessageBox::question(this,"Database","No database Exists."
43 | "Do you want to open your own database?",
44 | QMessageBox::Yes | QMessageBox::No);
45 | if(reply==QMessageBox::Yes)
46 | path = QFileDialog::getOpenFileName(this,"Database",QDir::currentPath());
47 | else{
48 | qApp->closeAllWindows();
49 | qApp->exit(0);
50 | }
51 | }
52 | db.setDatabaseName(path);
53 | qDebug() << path;
54 | if(db.open())
55 | ui->status->setText("Database Connected");
56 | else
57 | ui->status->setText("Database not connected");
58 | }
59 |
60 | void LoginDialog::login()
61 | {
62 | QString username = ui->username_edit->text();
63 | Factory *factory = new Factory(username,&db);
64 | factory->show();
65 | factory->showMaximized();
66 | this->hide();
67 | }
68 |
69 | LoginDialog::~LoginDialog()
70 | {
71 | delete ui;
72 | }
73 |
74 | void LoginDialog::on_pushButton_clicked()
75 | {
76 | QString username = ui->username_edit->text();
77 | QString password = ui->password_edit->text();
78 |
79 | QSqlQuery q(db);
80 | q.prepare("select * from users where username=? and password=?");
81 | q.bindValue(0,username);
82 | q.bindValue(1,password);
83 | if(q.exec())
84 | if(q.next()){
85 | int field = q.record().indexOf("username");
86 | ui->status->setText(q.value(field).toString()+" Logged in");
87 | login();
88 | }
89 | else
90 | ui->status->setText(username + " not found");
91 | else{
92 | ui->status->setText("Not logged in");
93 | QSqlError err = q.lastError();
94 | QMessageBox::warning(this,"Error",err.text());
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/logindialog.h:
--------------------------------------------------------------------------------
1 | #ifndef LOGINDIALOG_H
2 | #define LOGINDIALOG_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class LoginDialog;
9 | }
10 |
11 | class LoginDialog : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit LoginDialog(QWidget *parent = 0);
17 |
18 | bool checkLicence();
19 | void setupConnection();
20 | void login();
21 |
22 | ~LoginDialog();
23 |
24 | private slots:
25 | void on_pushButton_clicked();
26 |
27 | private:
28 | Ui::LoginDialog *ui;
29 | QSqlDatabase db;
30 | };
31 |
32 | #endif // LOGINDIALOG_H
33 |
--------------------------------------------------------------------------------
/logindialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | LoginDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 248
10 | 126
11 |
12 |
13 |
14 | Login
15 |
16 |
17 |
18 | :/images/img/login_icon.png:/images/img/login_icon.png
19 |
20 |
21 | -
22 |
23 |
-
24 |
25 |
-
26 |
27 |
-
28 |
29 |
30 |
31 | 75
32 | true
33 |
34 |
35 |
36 | username
37 |
38 |
39 |
40 | -
41 |
42 |
43 |
44 | 75
45 | true
46 |
47 |
48 |
49 | password
50 |
51 |
52 |
53 |
54 |
55 | -
56 |
57 |
-
58 |
59 |
60 | -
61 |
62 |
63 | QLineEdit::Password
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | Login
75 |
76 |
77 | Return
78 |
79 |
80 | true
81 |
82 |
83 |
84 |
85 |
86 | -
87 |
88 |
-
89 |
90 |
91 | Qt::Vertical
92 |
93 |
94 |
95 | 20
96 | 40
97 |
98 |
99 |
100 |
101 | -
102 |
103 |
104 | TextLabel
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include "logindialog.h"
2 | #include "application.h"
3 | #include
4 | #include
5 |
6 | int main(int argc, char *argv[])
7 | {
8 |
9 | Application a(argc, argv);
10 |
11 | if(a.dontShowMainWindow())
12 | return 0;
13 |
14 | return a.exec();
15 | }
16 |
--------------------------------------------------------------------------------
/paymentdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "paymentdialog.h"
2 | #include "ui_paymentdialog.h"
3 | #include
4 | #include
5 |
6 | PaymentDialog::PaymentDialog(QString dealer, QSqlDatabase *database,
7 | bool recieving,QWidget *parent) :
8 | db(database),
9 | QDialog(parent),
10 | _recieving(recieving),
11 | ui(new Ui::PaymentDialog)
12 | {
13 | ui->setupUi(this);
14 |
15 | //setup models
16 | ui->dateEdit->setDate(QDate::currentDate());
17 | ui->dealer_edit->setText(dealer);
18 | //set the debt
19 | if(_recieving)
20 | showDebt();
21 | else{
22 | showBalance();
23 | ui->recieve_button->setText("Pay");
24 | }
25 | }
26 |
27 | bool PaymentDialog::recievePayment()
28 | {
29 | QString dealer = ui->dealer_edit->text();
30 |
31 | QString money = ui->money_spinBox->text();
32 | QString date = ui->dateEdit->date().toString("yyyy-MM-dd");
33 |
34 | qDebug()<dealer_edit->text();
64 |
65 | QString money = ui->money_spinBox->text();
66 | QString date = ui->dateEdit->date().toString("yyyy-MM-dd");
67 | QString nature;
68 | if(_recieving)
69 | nature = "Recieved";
70 | else
71 | nature = "Paid";
72 |
73 | qDebug()<dealer_edit->text();
119 | q.exec("select debt from dealers where name = '"+dealer+"'");
120 | if(q.next())
121 | ui->balance_label->setText(q.value("debt").toString());
122 | }
123 |
124 | void PaymentDialog::showBalance()
125 | {
126 | QSqlQuery q(*db);
127 | QString supplier = ui->dealer_edit->text();
128 | q.exec("select balance from supplier where name = '"+supplier+"'");
129 | if(q.next())
130 | ui->balance_label->setText(q.value("balance").toString());
131 | }
132 |
133 | PaymentDialog::~PaymentDialog()
134 | {
135 | delete ui;
136 | }
137 |
138 | void PaymentDialog::on_recieve_button_clicked()
139 | {
140 | //confirms from the user
141 | QMessageBox::StandardButton reply;
142 | reply = QMessageBox::question(this,"Are You Sure?",
143 | "You can not undo the entry."
144 | "Do you want to continue?",
145 | QMessageBox::Yes | QMessageBox::Cancel);
146 | //if the user accepts the dialog
147 | if(reply==QMessageBox::Yes){
148 | //in case of pay
149 | if(_recieving){
150 | if(recievePayment()){
151 | QMessageBox::information(this,"Congratulations",
152 | "Payment Successfully recieved.");
153 | this->close();
154 | }
155 | }else{
156 | if(givePayment())
157 | QMessageBox::information(this,"Congratulations",
158 | "Payment Successfully paid.");
159 | this->close();
160 | }
161 |
162 | }
163 | }
164 |
165 | void PaymentDialog::on_money_spinBox_valueChanged(const QString &arg1)
166 | {
167 | Q_UNUSED(arg1);
168 | if(!(ui->dealer_edit->text().isEmpty())){
169 | ui->recieve_button->setEnabled(true);
170 | }
171 | else
172 | ui->recieve_button->setEnabled(false);
173 | }
174 |
--------------------------------------------------------------------------------
/paymentdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef PAYMENTDIALOG_H
2 | #define PAYMENTDIALOG_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class PaymentDialog;
9 | }
10 |
11 | class PaymentDialog : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit PaymentDialog(QString dealer, QSqlDatabase *db, bool recieving=true,
17 | QWidget *parent = 0);
18 | bool recievePayment();
19 | bool givePayment();
20 | bool removeDebt(QString dealer,QString money);
21 | void showDebt();
22 | void showBalance();
23 | ~PaymentDialog();
24 |
25 | private slots:
26 | void on_recieve_button_clicked();
27 | void on_money_spinBox_valueChanged(const QString &arg1);
28 |
29 | private:
30 | Ui::PaymentDialog *ui;
31 | QSqlDatabase *db;
32 | bool _recieving;
33 |
34 | };
35 |
36 | #endif // PAYMENTDIALOG_H
37 |
--------------------------------------------------------------------------------
/paymentdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | PaymentDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 223
10 | 164
11 |
12 |
13 |
14 | Payment
15 |
16 |
17 | -
18 |
19 |
-
20 |
21 |
-
22 |
23 |
-
24 |
25 |
26 |
27 | 12
28 | 75
29 | true
30 |
31 |
32 |
33 | Name
34 |
35 |
36 |
37 | -
38 |
39 |
40 |
41 | 12
42 | 75
43 | true
44 |
45 |
46 |
47 | Money
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 | 12
56 | 75
57 | true
58 |
59 |
60 |
61 | Date
62 |
63 |
64 |
65 |
66 |
67 | -
68 |
69 |
-
70 |
71 |
72 | false
73 |
74 |
75 |
76 | 10
77 | 75
78 | true
79 |
80 |
81 |
82 |
83 | -
84 |
85 |
86 |
87 | 12
88 | 75
89 | true
90 |
91 |
92 |
93 | 99999999
94 |
95 |
96 |
97 | -
98 |
99 |
100 | false
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | -
109 |
110 |
-
111 |
112 |
113 | false
114 |
115 |
116 | Recieve
117 |
118 |
119 |
120 | -
121 |
122 |
123 | Qt::Horizontal
124 |
125 |
126 |
127 | 40
128 | 20
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | -
138 |
139 |
-
140 |
141 |
142 |
143 | 12
144 | 75
145 | true
146 |
147 |
148 |
149 | Balance
150 |
151 |
152 |
153 | -
154 |
155 |
156 |
157 | 12
158 | 75
159 | true
160 | true
161 |
162 |
163 |
164 | color: rgb(255, 0, 0);
165 |
166 |
167 | Balance
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
--------------------------------------------------------------------------------
/paymentmodel.cpp:
--------------------------------------------------------------------------------
1 | #include "paymentmodel.h"
2 | #include
3 | #include
4 |
5 | PaymentModel::PaymentModel(QObject *parent, int namecolumn,
6 | int moneycolumn, int datecolumn, int timecolumn, int naturecolumn) :
7 | QSqlQueryModel(parent),
8 | _dealercolumn(namecolumn),
9 | _moneycolumn(moneycolumn),
10 | _datecolumn(datecolumn),
11 | _naturecolumn(naturecolumn)
12 | {
13 |
14 | }
15 |
16 | QVariant PaymentModel::data(const QModelIndex &index, int role) const
17 | {
18 | //name
19 | if(index.isValid() && index.column()==_dealercolumn &&
20 | role==Qt::ForegroundRole){
21 | QColor text;
22 | text.setNamedColor("#3f9fd1");
23 | return QVariant::fromValue(QBrush(text));
24 | }
25 | //money
26 | if(index.isValid() && index.column()==_moneycolumn &&
27 | role==Qt::ForegroundRole){
28 | QColor text;
29 | text.setNamedColor("#34a853");
30 | return QVariant::fromValue(QBrush(text));
31 | }
32 | //date
33 | if(index.isValid() && index.column()==_datecolumn &&
34 | role==Qt::ForegroundRole){
35 | QColor text;
36 | text.setNamedColor("#ea4335");
37 | return QVariant::fromValue(QBrush(text));
38 | }
39 | //time
40 | if(index.isValid() && index.column()==_datecolumn &&
41 | role==Qt::ForegroundRole){
42 | QColor text;
43 | text.setNamedColor("#bcbebf");
44 | return QVariant::fromValue(QBrush(text));
45 | }
46 | //nature
47 | if(index.isValid() && index.column()==_datecolumn &&
48 | role==Qt::ForegroundRole){
49 | QColor text;
50 | text.setNamedColor("#bcbebf");
51 | return QVariant::fromValue(QBrush(text));
52 | }
53 |
54 | return QSqlQueryModel::data(index,role);
55 | }
56 |
--------------------------------------------------------------------------------
/paymentmodel.h:
--------------------------------------------------------------------------------
1 | #ifndef PAYMENTMODEL_H
2 | #define PAYMENTMODEL_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | class PaymentModel : public QSqlQueryModel
13 | {
14 | Q_OBJECT
15 | public:
16 | PaymentModel(QObject *parent=nullptr,int namecolumn=0,
17 | int moneycolumn=1,int datecolumn=2,
18 | int timecolumn=3,int naturecolumn=4);
19 |
20 |
21 | protected:
22 | QVariant data(const QModelIndex &item, int role) const;
23 |
24 | private:
25 | int _dealercolumn;
26 | int _moneycolumn;
27 | int _datecolumn;
28 | int _naturecolumn;
29 | int _timecolumn;
30 | };
31 |
32 | #endif // PAYMENTMODEL_H
33 |
--------------------------------------------------------------------------------
/reportsdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "reportsdialog.h"
2 | #include "ui_reportsdialog.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | // pageborderclass
9 | class PrintBorder : public PagePrepare
10 | {
11 | public:
12 | virtual void preparePage(QPainter *painter);
13 | static int pageNumber;
14 | };
15 |
16 | int PrintBorder::pageNumber = 0;
17 |
18 | void PrintBorder::preparePage(QPainter *painter) { // print a border on each page
19 | QRect rec = painter->viewport();
20 | painter->setPen(QPen(QColor(0, 0, 0), 1));
21 | painter->drawRect(rec);
22 | painter->translate(10, painter->viewport().height() - 10);
23 | painter->drawText(0, 0, QString("Page %1").arg(pageNumber));
24 | pageNumber += 1;
25 | }
26 | //<---------------------------------------------------------------
27 |
28 |
29 | ReportsDialog::ReportsDialog(QSqlDatabase *database, QWidget *parent) :
30 | QDialog(parent),
31 | db(database),
32 | ui(new Ui::ReportsDialog)
33 | {
34 | ui->setupUi(this);
35 | if(!db->isOpen()){
36 | if(!db->open())
37 | QMessageBox::critical(this,"Database","Database is not opened.");
38 | reject();
39 | }
40 |
41 | //initialization
42 | initializeDateEdits();
43 | setupConnections();
44 | initializeModels();
45 | setupModels();
46 | setupDrawingVariables();
47 |
48 |
49 | }
50 |
51 | void ReportsDialog::initializeDateEdits()
52 | {
53 | //dealer tab
54 | ui->dealerfrom_dateEdit->setDate(QDate::currentDate().addDays(-7));
55 | ui->dealerto_dateEdit->setDate(QDate::currentDate());
56 |
57 | //supplier tab
58 | ui->supplierfrom_dateEdit_2->setDate(QDate::currentDate().addDays(-7));
59 | ui->supplierto_dateEdit_2->setDate(QDate::currentDate());
60 |
61 | }
62 |
63 | void ReportsDialog::initializeModels()
64 | {
65 | dealer_model = new QSqlQueryModel(this);
66 | supplier_model = new QSqlQueryModel(this);
67 | dealer_payments_model = new QSqlQueryModel(this);
68 | supplier_payments_model = new QSqlQueryModel(this);
69 | }
70 |
71 | void ReportsDialog::setupModels()
72 | {
73 | setupDealerTabModel();
74 | setupSupplierTabModel();
75 | }
76 |
77 | void ReportsDialog::setupConnections()
78 | {
79 | //connections
80 | //dealer tab
81 | connect(ui->dealerto_dateEdit,&QDateEdit::dateChanged,
82 | this,&ReportsDialog::loadDealerPayments);
83 | connect(ui->dealerfrom_dateEdit,&QDateEdit::dateChanged,
84 | this,&ReportsDialog::loadDealerPayments);
85 | connect(ui->dealer_comboBox,&QComboBox::currentTextChanged,
86 | this,&ReportsDialog::loadDealerPayments);
87 | //supplier tab
88 | connect(ui->supplierto_dateEdit_2,&QDateEdit::dateChanged,
89 | this,&ReportsDialog::loadSupplierPayments);
90 | connect(ui->supplierfrom_dateEdit_2,&QDateEdit::dateChanged,
91 | this,&ReportsDialog::loadSupplierPayments);
92 | connect(ui->supplier_comboBox_2,&QComboBox::currentTextChanged,
93 | this,&ReportsDialog::loadSupplierPayments);
94 | }
95 |
96 | void ReportsDialog::setupDealerTabModel()
97 | {
98 | /// Combo box
99 | // execute query
100 | QSqlQuery q(*db);
101 | q.prepare("select name from dealers");
102 | if(!q.exec()){
103 | QSqlError err = q.lastError();
104 | QMessageBox::critical(this,"Error","Could not load the"
105 | " dealers "+err.text());
106 | return;
107 | }
108 | dealer_model->setQuery(q);
109 | //set views
110 | ui->dealer_comboBox->setModel(dealer_model);
111 |
112 | //load payment details
113 | loadDealerPayments();
114 | }
115 |
116 | void ReportsDialog::setupSupplierTabModel()
117 | {
118 | //execute queries
119 | QSqlQuery q(*db);
120 | q.prepare("select name from supplier");
121 | if(!q.exec()){
122 | QSqlError err = q.lastError();
123 | QMessageBox::critical(this,"Error","Could not load the"
124 | " supplier "+err.text());
125 | return;
126 | }
127 |
128 | //set views
129 | supplier_model->setQuery(q);
130 | ui->supplier_comboBox_2->setModel(supplier_model);
131 | loadSupplierPayments();
132 | }
133 |
134 | void ReportsDialog::setupDrawingVariables()
135 | {
136 | colStretch = QVector() << 5 << 10 << 10 << 10 << 10 << 10;
137 | headers = QVector() << "ID" << "پارٹی" << "رقم" << "تاریخ"
138 | << "وقت" << "Nature";
139 | _factoryName = "786 پلاسٹکس";
140 | }
141 |
142 | void ReportsDialog::loadDealerPayments()
143 | {
144 | QSqlQuery q(*db);
145 | q.prepare("select serial,dealer,money,date,time,nature from payments"
146 | " where dealer=? and date>? and date and nature=?");
147 | q.bindValue(0,ui->dealer_comboBox->currentText());
148 | q.bindValue(1,ui->dealerfrom_dateEdit->date().addDays(-1).toString("yyyy-MM-dd"));
149 | q.bindValue(2,ui->dealerto_dateEdit->date().addDays(1).toString("yyyy-MM-dd"));
150 | q.bindValue(3,"Recieved");
151 |
152 | if(!q.exec()){
153 | QSqlError err = q.lastError();
154 | QMessageBox::critical(this,"Error","Could not load the"
155 | " payments "+err.text());
156 | return;
157 | }
158 | //set view
159 | dealer_payments_model->setQuery(q);
160 | ui->dealer_tableview->setModel(dealer_payments_model);
161 | }
162 |
163 | void ReportsDialog::loadSupplierPayments()
164 | {
165 | QSqlQuery q(*db);
166 | q.prepare("select * from payments"
167 | " where dealer=? and date>? and date and nature=?");
168 | q.bindValue(0,ui->supplier_comboBox_2->currentText());
169 | q.bindValue(1,ui->supplierfrom_dateEdit_2->date().addDays(-1).toString("yyyy-MM-dd"));
170 | q.bindValue(2,ui->supplierto_dateEdit_2->date().addDays(1).toString("yyyy-MM-dd"));
171 | q.bindValue(3,"Paid");
172 |
173 | if(!q.exec()){
174 | QSqlError err = q.lastError();
175 | QMessageBox::critical(this,"Error","Could not load the"
176 | " payments "+err.text());
177 | return;
178 | }
179 | //set view
180 | supplier_payments_model->setQuery(q);
181 | ui->supplier_tableView->setModel(supplier_payments_model);
182 | }
183 |
184 | void ReportsDialog::dealerUglyPrint(QPrinter *printer) {
185 |
186 | // ---------------- death-to-designers ------------------
187 |
188 | QPainter uglyPainter;
189 | if(!uglyPainter.begin(printer)) {
190 | qWarning() << "can't start printer";
191 | return;
192 | }
193 | TablePrinter uglyTablePrinter(&uglyPainter, printer);
194 | uglyTablePrinter.setPen(QPen(QColor(0, 0, 0), 3, Qt::SolidLine)); // pen for borders
195 | uglyTablePrinter.setHeaderColor(QColor(Qt::black));
196 | uglyTablePrinter.setContentColor(Qt::black);
197 | QFont font1; // font for headers
198 | font1.setPixelSize(16);
199 | font1.setBold(true);
200 | font1.setWeight(QFont::DemiBold);
201 | QFont font2; // font for content
202 | font2.setItalic(true);
203 | uglyTablePrinter.setHeadersFont(font1);
204 | uglyTablePrinter.setContentFont(font2);
205 | PrintBorder *printB = new PrintBorder;
206 | printB->pageNumber = 1;
207 | uglyTablePrinter.setPagePrepare(printB);
208 | uglyPainter.setPen(QPen(Qt::black));
209 | QFont titleFont;
210 | titleFont.setFamily("arial");
211 | titleFont.setWeight(QFont::Black);
212 | titleFont.setPixelSize(26);
213 | uglyPainter.setFont(titleFont);
214 | uglyPainter.drawText(uglyPainter.viewport().width()/2 - 40, 40, _factoryName);
215 | uglyPainter.translate(0, 60); // start print point
216 | uglyTablePrinter.setCellMargin(10, 5, 5, 5);
217 | uglyTablePrinter.setPageMargin(100, 40, 40, 40);
218 | if(!uglyTablePrinter.printTable(ui->dealer_tableview->model(), colStretch, headers)) {
219 | qDebug() << uglyTablePrinter.lastError();
220 | }
221 | uglyPainter.end();
222 | delete printB;
223 | }
224 |
225 | void ReportsDialog::supplierUglyPrint(QPrinter *printer)
226 | {
227 | // ---------------- death-to-designers ------------------
228 |
229 | QPainter uglyPainter;
230 | if(!uglyPainter.begin(printer)) {
231 | qWarning() << "can't start printer";
232 | return;
233 | }
234 | TablePrinter uglyTablePrinter(&uglyPainter, printer);
235 | uglyTablePrinter.setPen(QPen(QColor(0, 0, 0), 3, Qt::SolidLine)); // pen for borders
236 | uglyTablePrinter.setHeaderColor(QColor(Qt::black));
237 | uglyTablePrinter.setContentColor(Qt::black);
238 | QFont font1; // font for headers
239 | font1.setBold(true);
240 | font1.setWeight(QFont::DemiBold);
241 | QFont font2; // font for content
242 | font2.setItalic(true);
243 | uglyTablePrinter.setHeadersFont(font1);
244 | uglyTablePrinter.setContentFont(font2);
245 | PrintBorder *printB = new PrintBorder;
246 | printB->pageNumber = 1;
247 | uglyTablePrinter.setPagePrepare(printB);
248 | uglyPainter.setPen(QPen(Qt::black));
249 | uglyPainter.drawText(uglyPainter.viewport().width()/2 - 40, 40, _factoryName);
250 | uglyPainter.translate(0, 60); // start print point
251 | uglyTablePrinter.setCellMargin(10, 5, 5, 5);
252 | uglyTablePrinter.setPageMargin(100, 40, 40, 40);
253 | if(!uglyTablePrinter.printTable(ui->supplier_tableView->model(), colStretch, headers)) {
254 | qDebug() << uglyTablePrinter.lastError();
255 | }
256 | uglyPainter.end();
257 | delete printB;
258 | }
259 |
260 | ReportsDialog::~ReportsDialog()
261 | {
262 | delete ui;
263 | }
264 |
265 | void ReportsDialog::on_printDealerPayment_toolButton_clicked()
266 | {
267 | QPrintPreviewDialog *dialog = new QPrintPreviewDialog;
268 | dialog->setAttribute(Qt::WA_DeleteOnClose);
269 | connect(dialog,&QPrintPreviewDialog::paintRequested,
270 | this,&ReportsDialog::dealerUglyPrint);
271 | dialog->exec();
272 | }
273 |
274 | void ReportsDialog::on_printsupplierpayments_toolbutton_clicked()
275 | {
276 | QPrintPreviewDialog *dialog = new QPrintPreviewDialog;
277 | dialog->setAttribute(Qt::WA_DeleteOnClose);
278 | connect(dialog,&QPrintPreviewDialog::paintRequested,
279 | this,&ReportsDialog::supplierUglyPrint);
280 | dialog->exec();
281 | }
282 |
--------------------------------------------------------------------------------
/reportsdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef REPORTSDIALOG_H
2 | #define REPORTSDIALOG_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "tableprinter.h"
12 | #include
13 |
14 | namespace Ui {
15 | class ReportsDialog;
16 | }
17 |
18 | class ReportsDialog : public QDialog
19 | {
20 | Q_OBJECT
21 |
22 | public:
23 | explicit ReportsDialog(QSqlDatabase *db,QWidget *parent = 0);
24 | void initializeDateEdits();
25 | void initializeModels();
26 | void setupModels();
27 | void setupConnections();
28 | void setupDealerTabModel();
29 | void setupSupplierTabModel();
30 | void setupDrawingVariables();
31 |
32 | ~ReportsDialog();
33 |
34 | public slots:
35 | void loadDealerPayments();
36 | void loadSupplierPayments();
37 | void dealerUglyPrint(QPrinter *printer);
38 | void supplierUglyPrint(QPrinter *printer);
39 |
40 | private slots:
41 | void on_printDealerPayment_toolButton_clicked();
42 | void on_printsupplierpayments_toolbutton_clicked();
43 |
44 | private:
45 | Ui::ReportsDialog *ui;
46 | QSqlDatabase *db;
47 | QSqlQueryModel *dealer_model;
48 | QSqlQueryModel *supplier_model;
49 | QSqlQueryModel *dealer_payments_model;
50 | QSqlQueryModel *supplier_payments_model;
51 | //for reports
52 | QVector colStretch;
53 | QVector headers;
54 | QString _factoryName;
55 | };
56 |
57 | #endif // REPORTSDIALOG_H
58 |
--------------------------------------------------------------------------------
/reportsdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | ReportsDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 455
10 | 425
11 |
12 |
13 |
14 | Reports
15 |
16 |
17 | -
18 |
19 |
20 | 0
21 |
22 |
23 |
24 | Dealer
25 |
26 |
27 |
-
28 |
29 |
-
30 |
31 |
-
32 |
33 |
34 | background-color: rgb(64, 66, 68);
35 | color: rgb(146, 189, 108);
36 | font: 14pt "Sans Serif";
37 |
38 |
39 |
40 | -
41 |
42 |
43 | background-color: rgb(64, 66, 68);
44 | color: rgb(146, 189, 108);
45 | font: 14pt "Sans Serif";
46 |
47 |
48 | dd-MM-yyyy
49 |
50 |
51 |
52 | -
53 |
54 |
55 | background-color: rgb(64, 66, 68);
56 | color: rgb(146, 189, 108);
57 | font: 14pt "Sans Serif";
58 |
59 |
60 | dd-MM-yyyy
61 |
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 | ...
70 |
71 |
72 |
73 | -
74 |
75 |
76 | Qt::Horizontal
77 |
78 |
79 |
80 | 40
81 | 20
82 |
83 |
84 |
85 |
86 |
87 |
88 | -
89 |
90 |
91 |
92 |
93 |
94 |
95 | Supplier
96 |
97 |
98 | -
99 |
100 |
-
101 |
102 |
-
103 |
104 |
105 | background-color: rgb(64, 66, 68);
106 | color: rgb(146, 189, 108);
107 | font: 14pt "Sans Serif";
108 |
109 |
110 |
111 | -
112 |
113 |
114 | background-color: rgb(64, 66, 68);
115 | color: rgb(146, 189, 108);
116 | font: 14pt "Sans Serif";
117 |
118 |
119 | dd-MM-yyyy
120 |
121 |
122 |
123 | -
124 |
125 |
126 | background-color: rgb(64, 66, 68);
127 | color: rgb(146, 189, 108);
128 | font: 14pt "Sans Serif";
129 |
130 |
131 | dd-MM-yyyy
132 |
133 |
134 |
135 |
136 |
137 | -
138 |
139 |
140 | ...
141 |
142 |
143 |
144 | -
145 |
146 |
147 | Qt::Horizontal
148 |
149 |
150 |
151 | 40
152 | 20
153 |
154 |
155 |
156 |
157 |
158 |
159 | -
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/resource.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | Records/database.db
4 |
5 |
6 | img/login_icon.png
7 | img/Buy-48.png
8 | img/Sell Stock-64.png
9 | img/cash-payment-icon-5.png
10 | img/20160528014858.jpg
11 | img/dealers_icon.jpg
12 | img/diyarbakir-nakliyat.jpg
13 | img/fork5.png
14 | img/gconstruct1-06.png
15 | img/home-content-dealer-icon.png
16 | img/icon_suppliers.png
17 | img/payment-clipart-k9923905.jpg
18 | img/sales-icon-large.png
19 | img/supplier_icon.png
20 | img/User-icon.png
21 | img/back.jpg
22 | img/main.png
23 |
24 |
25 |
--------------------------------------------------------------------------------
/salesmodel.cpp:
--------------------------------------------------------------------------------
1 | #include "salesmodel.h"
2 |
3 | SalesModel::SalesModel(QObject *parent, int serial, int name,
4 | int weight, int total, int paid, int remaining) :
5 | QSqlQueryModel(parent),
6 | _serial(serial),
7 | _name(name),
8 | _weight(weight),
9 | _total(total),
10 | _paid(paid),
11 | _remaining(remaining)
12 | {
13 |
14 | }
15 |
16 | QVariant SalesModel::data(const QModelIndex &index, int role) const
17 | {
18 | //serial no
19 | if(index.isValid() && index.column()==_serial && role==Qt::ForegroundRole){
20 | QColor text;
21 | text.setNamedColor("#ea4335");//google red
22 | return QBrush(text);
23 | }
24 | //name
25 | if(index.isValid() && index.column()==_name && role==Qt::ForegroundRole){
26 | QColor text;
27 | text.setNamedColor("#4285f4");//google blue
28 | return QBrush(text);
29 | }
30 | //paid price
31 | if(index.isValid() && index.column()==_paid && role==Qt::ForegroundRole){
32 | QColor text;
33 | text.setNamedColor("#ba6000");//qt orange
34 | return QBrush(text);
35 | }
36 | //total price
37 | if(index.isValid() && index.column()==_total && role==Qt::ForegroundRole){
38 | QColor text;
39 | text.setNamedColor("#34a853");//google green
40 | return QBrush(text);
41 | }
42 | //weight
43 | if(index.isValid() && index.column()==_paid && role==Qt::ForegroundRole){
44 | QColor text;
45 | text.setNamedColor("#ba6000");//qt orange
46 | return QBrush(text);
47 | }
48 | // cash remaining
49 | if(index.isValid() && index.column()==_remaining && role==Qt::ForegroundRole){
50 | QColor text;
51 | text.setNamedColor("#ea4335");//google red
52 | return QBrush(text);
53 | }
54 | //other color
55 | if(index.isValid() && role==Qt::ForegroundRole){
56 | QColor text;
57 | text.setNamedColor("#404244");//maingery
58 | return QBrush(text);
59 | }
60 | //font
61 | if(index.isValid() && role==Qt::FontRole){
62 | return QFont("times",12,QFont::DemiBold);
63 | }
64 | return QSqlQueryModel::data(index,role);
65 | }
66 |
67 | int SalesModel::weight() const
68 | {
69 | return _weight;
70 | }
71 |
72 | void SalesModel::setWeight(int weight)
73 | {
74 | _weight = weight;
75 | }
76 |
77 | int SalesModel::paid() const
78 | {
79 | return _paid;
80 | }
81 |
82 | void SalesModel::setPaid(int paid)
83 | {
84 | _paid = paid;
85 | }
86 |
87 | int SalesModel::total() const
88 | {
89 | return _total;
90 | }
91 |
92 | void SalesModel::setTotal(int total)
93 | {
94 | _total = total;
95 | }
96 |
97 | int SalesModel::name() const
98 | {
99 | return _name;
100 | }
101 |
102 | void SalesModel::setName(int name)
103 | {
104 | _name = name;
105 | }
106 |
107 |
108 |
109 | int SalesModel::serial() const
110 | {
111 | return _serial;
112 | }
113 |
114 | void SalesModel::setSerial(int serial)
115 | {
116 | _serial = serial;
117 | }
118 |
--------------------------------------------------------------------------------
/salesmodel.h:
--------------------------------------------------------------------------------
1 | #ifndef SALESMODEL_H
2 | #define SALESMODEL_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | class SalesModel : public QSqlQueryModel
12 | {
13 | Q_OBJECT
14 | public:
15 | explicit SalesModel(QObject *parent=nullptr,int serial=0,int name=1,int weight=2,
16 | int total=3,int paid=4,int remaining=5);
17 |
18 | int serial() const;
19 | void setSerial(int serial);
20 |
21 | int name() const;
22 | void setName(int name);
23 |
24 | int total() const;
25 | void setTotal(int total);
26 |
27 | int paid() const;
28 | void setPaid(int paid);
29 |
30 | int weight() const;
31 | void setWeight(int weight);
32 |
33 | protected:
34 | QVariant data(const QModelIndex &index, int role) const;
35 |
36 | private:
37 | int _serial;
38 | int _name;
39 | int _total;
40 | int _paid;
41 | int _weight;
42 | int _remaining;
43 | };
44 |
45 | #endif // SALESMODEL_H
46 |
--------------------------------------------------------------------------------
/selldialog.cpp:
--------------------------------------------------------------------------------
1 | #include "selldialog.h"
2 | #include "ui_selldialog.h"
3 |
4 | SellDialog::SellDialog(QString dealer, QSqlDatabase *database, QSqlQueryModel *dealers_model,
5 | QSqlQueryModel *materials_model, QWidget *parent) :
6 | db(database),
7 | QDialog(parent),
8 | ui(new Ui::SellDialog)
9 | {
10 | Q_ASSERT(dealers_model != Q_NULLPTR);
11 | Q_ASSERT(database != Q_NULLPTR);
12 |
13 | ui->setupUi(this);
14 | ui->dateTimeEdit->setDate(QDate::currentDate());
15 |
16 | //check database
17 | if(!db->open()){
18 | QMessageBox::critical(this,"Database","The database couldn't"
19 | "be connected.");
20 | ui->status_label->setText("Database not connected");
21 | }else
22 | ui->status_label->setText("Database connected");
23 |
24 | //update model
25 | setupModels(dealers_model,materials_model);
26 | ui->dealer_edit->setText(dealer);
27 | //set the debt
28 | QSqlQuery q(*db);
29 | q.prepare("select debt from dealers where name=?");
30 | q.bindValue(0,dealer);
31 | if(!q.exec()){
32 | QSqlError err = q.lastError();
33 | QMessageBox::warning(this,"Balance",
34 | "Couldn't load balance due to "+ err.text());
35 | return;
36 | }
37 | if(q.next())
38 | ui->debt_label->setText(q.value("debt").toString());
39 | }
40 |
41 | void SellDialog::setupModels(QSqlQueryModel *dealer,QSqlQueryModel *material)
42 | {
43 | //set DateTime
44 | ui->dateTimeEdit->setDate(QDate::currentDate());
45 | //update statistics
46 | QString total_stock = QString(getTotalStock());
47 | ui->totalstock_edit->setText(total_stock);
48 | //list view model/////////////////////////////
49 | setupListModel(dealer);
50 | //combo box model/////////////////////////////
51 | setupComboboxModel(material);
52 | }
53 |
54 | bool SellDialog::doDeal()
55 | {
56 | //start transaction
57 | transacting = true;
58 | db->transaction();
59 | //prepare items for query
60 | QString dealer = ui->dealer_edit->text();
61 | QString material = ui->material_combo->currentText();
62 | qint64 quantity = ui->quantity_spinbox->value();
63 | qint64 price_per_unit = ui->cost_spinbox->value();
64 | qint64 total = ui->total_spinbox->value();
65 | qint64 cash_paid = ui->cashpaid_spinbox->value();
66 | QString date = ui->dateTimeEdit->date().toString("yyyy-MM-dd");
67 | //calculate remaining cash
68 | qint64 remaining = total - cash_paid;
69 |
70 | QSqlQuery q(*db);
71 | //prepare the query
72 | q.prepare("insert into deals(dealer,material,price_per_unit,"
73 | "cash_paid,date,quantity,cash_remaining,total) "
74 | "values(:dealer,:material,:price_per_unit,"
75 | ":cash_paid,:date,:quantity,:cash_remaining,:total)");
76 | q.bindValue(":dealer",dealer);
77 | q.bindValue(":material",material);
78 | q.bindValue(":price_per_unit",price_per_unit);
79 | q.bindValue(":cash_paid",cash_paid);
80 | q.bindValue(":date",date);
81 | q.bindValue(":quantity",quantity);
82 | q.bindValue(":cash_remaining",remaining);
83 | q.bindValue(":total",total);
84 |
85 | if(!q.exec()){
86 | QSqlError err = q.lastError();
87 | QMessageBox::critical(this,"Error",err.text());
88 | db->rollback();
89 | return false;
90 | }
91 |
92 | //calculate the stock left
93 | if(!updateStockAfterDeal(material,quantity)){
94 | db->rollback();
95 | transacting=false;
96 | return false;
97 | }
98 | //calculate debt
99 | if(!updateDebtAfterDeal(dealer,cash_paid,total)){
100 | db->rollback();
101 | transacting=false;
102 | return false;
103 | }
104 |
105 | //everything goes well then commit
106 | db->commit();
107 | transacting=false;
108 | return true;
109 | }
110 |
111 | void SellDialog::setupListModel(QSqlQueryModel *model)
112 | {
113 | QSqlQuery q(*db);
114 | QString query = "select name from dealers order by name";
115 |
116 | //execute the query
117 | if(!q.exec(query)){
118 | QSqlError err = q.lastError();
119 | QMessageBox::warning(this,"Dealer List","The query for dealers"
120 | "couldn't be executed.Error :"
121 | " "+err.text());
122 | }
123 |
124 | //set model
125 | model->setQuery(q);
126 | ui->dealers_view->setModel(model);
127 | }
128 |
129 | void SellDialog::setupComboboxModel(QSqlQueryModel *model)
130 | {
131 | QSqlQuery q(*db);
132 | //execute the query
133 | if(!q.exec("select type from materials order by type")){
134 | QSqlError err = q.lastError();
135 | QMessageBox::warning(this,"Material List",err.text());
136 | }
137 | //set the model
138 | model->setQuery(q);
139 | ui->material_combo->setModel(model);
140 | }
141 |
142 | QString SellDialog::getTotalStock()
143 | {
144 | QSqlQuery q(*db);
145 | QString material=ui->material_combo->currentText();
146 | q.prepare("select quantity from materials where type=?");
147 | q.bindValue(0,material);
148 | if(!q.exec()){
149 | QSqlError err = q.lastError();
150 | QMessageBox::warning(this,"Total Stock",err.text());
151 | return "Error";
152 | }
153 | QString stock;
154 | if(q.next())
155 | stock = q.value("quantity").toString();
156 | return stock;
157 | }
158 |
159 | bool SellDialog::updateStockAfterDeal(QString material,qint64 quantity)
160 | {
161 | QSqlQuery q(*db);
162 | q.prepare("update materials set quantity=quantity-? where type=?");
163 | q.bindValue(0,quantity);
164 | q.bindValue(1,material);
165 | if(!q.exec()){
166 | QSqlError err = q.lastError();
167 | QMessageBox::critical(this,"Error","Could't update stock .\n"+err.text());
168 | return false;
169 | }
170 | return true;
171 | }
172 |
173 | bool SellDialog::updateDebtAfterDeal(QString dealer, qint64 paid, qint64 total)
174 | {
175 | if(paid != total){
176 | qint64 debt = total - paid;
177 | QSqlQuery q(*db);
178 | q.prepare("update dealers set debt=debt+? where name=?");
179 | q.bindValue(0,debt);
180 | q.bindValue(1,dealer);
181 | if(!q.exec()){
182 | QSqlError err = q.lastError();
183 | QMessageBox::critical(this,"Error","Could't update balance .\n"+err.text());
184 | return false;
185 | }
186 | return true;
187 | }
188 | return true;
189 | }
190 |
191 | bool SellDialog::isAnyFieldEmpty()
192 | {
193 | if(ui->dealer_edit->text().isEmpty() ||
194 | ui->material_combo->currentText().isEmpty() ||
195 | ui->total_spinbox->value()<1 ||
196 | ui->total_spinbox->text().isEmpty() ||
197 | ui->cashpaid_spinbox->text().isEmpty() ||
198 | ui->cost_spinbox->text().isEmpty() ||
199 | ui->quantity_spinbox->value()<1 ||
200 | ui->quantity_spinbox->text().isEmpty())
201 | return true;
202 | return false;
203 | }
204 |
205 |
206 | SellDialog::~SellDialog()
207 | {
208 | delete ui;
209 | }
210 |
211 | void SellDialog::on_toolButton_clicked()
212 | {
213 | if(ui->total_spinbox->isReadOnly())
214 | ui->total_spinbox->setReadOnly(false);
215 | else
216 | ui->total_spinbox->setReadOnly(true);
217 | }
218 |
219 | void SellDialog::on_dealers_view_clicked(const QModelIndex &index)
220 | {
221 | QString dealer_name = index.data().toString();
222 | ui->dealer_edit->setText(dealer_name);
223 |
224 | //set the debt
225 | QSqlQuery q(*db);
226 | q.exec("select debt from dealers where name = '"+dealer_name+"'");
227 | if(q.next())
228 | ui->debt_label->setText(q.value("debt").toString());
229 | }
230 |
231 | void SellDialog::on_reset_button_clicked()
232 | {
233 | ui->dealer_edit->clear();
234 | ui->quantity_spinbox->clear();
235 | ui->cost_spinbox->clear();
236 | ui->total_spinbox->clear();
237 | ui->cashpaid_spinbox->clear();
238 | ui->total_spinbox->setEnabled(false);
239 | ui->totalstock_edit->setText(getTotalStock());
240 | }
241 |
242 | void SellDialog::on_deal_button_clicked()
243 | {
244 | //check fields
245 | if(isAnyFieldEmpty()){
246 | QMessageBox::warning(this,"Empty Fields",
247 | "Please Fill in the empty fields");
248 | return;
249 | }
250 |
251 | //confirms from the user
252 | QMessageBox::StandardButton reply;
253 | reply = QMessageBox::question(this,"Are You Sure?",
254 | "You can not undo the entry."
255 | "Do you want to continue?",
256 | QMessageBox::Yes | QMessageBox::Cancel);
257 | //if the user accepts the dialog
258 | if(reply == QMessageBox::Yes){
259 | if(doDeal())
260 | QMessageBox::information(this,"Done","Deal successfully done");
261 | else
262 | return;
263 | accept();
264 | }
265 | //else if he denies the dialog
266 | else if(reply==QMessageBox::Cancel){
267 | return;
268 | }
269 | }
270 |
271 | void SellDialog::on_dealer_edit_textChanged(const QString &arg1)
272 | {
273 | Q_UNUSED(arg1);
274 |
275 | if(ui->dealer_edit->text().isEmpty())
276 | ui->deal_button->setEnabled(false);
277 | else
278 | ui->deal_button->setEnabled(true);
279 | }
280 |
281 | void SellDialog::on_material_combo_currentIndexChanged(const QString &arg1)
282 | {
283 | QString material = arg1;
284 | QSqlQuery q(*db);
285 | q.prepare("select quantity from materials where type=?");
286 | q.bindValue(0,material);
287 | if(!q.exec()){
288 | QSqlError err = q.lastError();
289 | QMessageBox::critical(this,"Error",err.text());
290 | return;
291 | }else{
292 | q.next();
293 | qint64 stock= q.value("quantity").toLongLong();
294 | ui->totalstock_edit->setText(QString::number(stock));
295 | ui->quantity_spinbox->setMaximum(stock);
296 | }
297 | }
298 |
299 | void SellDialog::on_cost_spinbox_valueChanged(int arg1)
300 | {
301 | qint64 quantity = ui->quantity_spinbox->value();
302 | qint64 total = arg1 * quantity;
303 | ui->total_spinbox->setValue(total);
304 | }
305 |
306 | void SellDialog::on_quantity_spinbox_valueChanged(int arg1)
307 | {
308 | qint64 cost_per_unit = ui->cost_spinbox->value();
309 | qint64 total= cost_per_unit * arg1;
310 | ui->total_spinbox->setValue(total);
311 |
312 | //check total stock
313 | int total_stock = ui->totalstock_edit->text().toInt();
314 | if(arg1>total_stock){
315 | ui->deal_button->setEnabled(false);
316 | }else
317 | ui->deal_button->setEnabled(true);
318 | }
319 |
--------------------------------------------------------------------------------
/selldialog.h:
--------------------------------------------------------------------------------
1 | #ifndef SELLDIALOG_H
2 | #define SELLDIALOG_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace Ui {
9 | class SellDialog;
10 | }
11 |
12 | class SellDialog : public QDialog
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit SellDialog(QString dealer, QSqlDatabase *database, QSqlQueryModel *dealers_model,
18 | QSqlQueryModel *materials_model,QWidget *parent = 0);
19 |
20 | void setupModels(QSqlQueryModel *dealer, QSqlQueryModel *material);
21 | bool doDeal();
22 | void setupListModel(QSqlQueryModel *model);
23 | void setupComboboxModel(QSqlQueryModel *model);
24 | QString getTotalStock();
25 | bool updateStockAfterDeal(QString material, qint64 quantity);
26 | bool updateDebtAfterDeal(QString dealer, qint64 paid, qint64 total_price);
27 | bool isAnyFieldEmpty();
28 |
29 | ~SellDialog();
30 |
31 | private slots:
32 | void on_toolButton_clicked();
33 | void on_dealers_view_clicked(const QModelIndex &index);
34 | void on_reset_button_clicked();
35 | void on_deal_button_clicked();
36 | void on_dealer_edit_textChanged(const QString &arg1);
37 | void on_material_combo_currentIndexChanged(const QString &arg1);
38 |
39 | void on_cost_spinbox_valueChanged(int arg1);
40 |
41 | void on_quantity_spinbox_valueChanged(int arg1);
42 |
43 | private:
44 | Ui::SellDialog *ui;
45 | QSqlDatabase *db;
46 | bool transacting = false;
47 | };
48 |
49 | #endif // SELLDIALOG_H
50 |
--------------------------------------------------------------------------------
/selldialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | SellDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 737
10 | 452
11 |
12 |
13 |
14 | Sell
15 |
16 |
17 |
18 |
19 |
20 | -
21 |
22 |
-
23 |
24 |
-
25 |
26 |
-
27 |
28 |
29 | background-color: rgb(255, 255, 255);
30 | font: 87 14pt "Segoe UI Black";
31 | color: rgb(234, 67, 53);
32 |
33 |
34 | dd-MMM
35 |
36 |
37 |
38 | -
39 |
40 |
41 |
42 | 14
43 | 75
44 | true
45 |
46 |
47 |
48 | background-color: rgb(0, 85, 255);
49 | background-image: url(:/images/img/grren_login_screen_by_h2o4life-d3181xz.png);
50 |
51 |
52 | <html><head/><body><p><span style=" color:#ff0000;">786 Plastics</span></p></body></html>
53 |
54 |
55 | Qt::RichText
56 |
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
-
64 |
65 |
66 | Qt::Horizontal
67 |
68 |
69 |
70 | 40
71 | 20
72 |
73 |
74 |
75 |
76 | -
77 |
78 |
-
79 |
80 |
81 |
82 | Segoe UI Semibold
83 | 16
84 | 75
85 | true
86 | true
87 | true
88 |
89 |
90 |
91 | background-color: rgb(255, 255, 255);
92 | color: rgb(64, 66, 68);
93 |
94 |
95 | Stock
96 |
97 |
98 |
99 | -
100 |
101 |
102 | false
103 |
104 |
105 |
106 | 25
107 | 75
108 | true
109 |
110 |
111 |
112 | background-color: rgb(255, 255, 255);
113 | color: rgb(66, 133, 244);
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 | -
122 |
123 |
-
124 |
125 |
-
126 |
127 |
-
128 |
129 |
-
130 |
131 |
132 |
133 | 11
134 | 75
135 | true
136 |
137 |
138 |
139 | Buyer
140 |
141 |
142 | dealer_edit
143 |
144 |
145 |
146 | -
147 |
148 |
149 |
150 | 12
151 | 75
152 | true
153 |
154 |
155 |
156 | Material
157 |
158 |
159 | material_combo
160 |
161 |
162 |
163 | -
164 |
165 |
166 |
167 | 12
168 | 75
169 | true
170 |
171 |
172 |
173 | Cost Per unit
174 |
175 |
176 | cost_spinbox
177 |
178 |
179 |
180 | -
181 |
182 |
183 |
184 | 12
185 | 75
186 | true
187 |
188 |
189 |
190 | Quantity
191 |
192 |
193 | quantity_spinbox
194 |
195 |
196 |
197 | -
198 |
199 |
200 |
201 | 12
202 | 75
203 | true
204 |
205 |
206 |
207 | Total
208 |
209 |
210 | total_spinbox
211 |
212 |
213 |
214 | -
215 |
216 |
217 |
218 | 12
219 | 75
220 | true
221 |
222 |
223 |
224 | Cash Paid
225 |
226 |
227 | cashpaid_spinbox
228 |
229 |
230 |
231 |
232 |
233 | -
234 |
235 |
-
236 |
237 |
238 |
239 | MS Shell Dlg 2
240 | 16
241 | 50
242 | false
243 | false
244 |
245 |
246 |
247 | background-color: rgb(1, 55, 65);
248 | color: rgb(230, 230, 230);
249 |
250 |
251 | true
252 |
253 |
254 |
255 | -
256 |
257 |
258 |
259 | 16
260 | 75
261 | true
262 |
263 |
264 |
265 |
266 | -
267 |
268 |
269 |
270 | 16
271 | 75
272 | true
273 |
274 |
275 |
276 | 1
277 |
278 |
279 | 99999999
280 |
281 |
282 |
283 | -
284 |
285 |
286 |
287 | 16
288 | 75
289 | true
290 |
291 |
292 |
293 | 1
294 |
295 |
296 | 99999999
297 |
298 |
299 |
300 | -
301 |
302 |
-
303 |
304 |
305 | false
306 |
307 |
308 |
309 | 20
310 | 75
311 | true
312 |
313 |
314 |
315 | background-color: rgb(64, 66, 68);
316 | color: rgb(146, 189, 108);
317 |
318 |
319 | 0
320 |
321 |
322 | 99999999
323 |
324 |
325 | 0
326 |
327 |
328 |
329 | -
330 |
331 |
332 | ...
333 |
334 |
335 |
336 |
337 |
338 | -
339 |
340 |
341 |
342 | 16
343 | 75
344 | true
345 |
346 |
347 |
348 | color: rgb(186, 96, 0);
349 |
350 |
351 | 0
352 |
353 |
354 | 99999999
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 | -
363 |
364 |
365 |
366 |
367 | -
368 |
369 |
-
370 |
371 |
-
372 |
373 |
374 | false
375 |
376 |
377 | Deal
378 |
379 |
380 |
381 | -
382 |
383 |
384 | Reset
385 |
386 |
387 | false
388 |
389 |
390 |
391 |
392 |
393 | -
394 |
395 |
396 | Qt::Horizontal
397 |
398 |
399 |
400 | 325
401 | 13
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 | -
413 |
414 |
-
415 |
416 |
-
417 |
418 |
419 | Qt::Horizontal
420 |
421 |
422 |
423 | 40
424 | 20
425 |
426 |
427 |
428 |
429 | -
430 |
431 |
432 | Qt::Horizontal
433 |
434 |
435 |
436 | 38
437 | 20
438 |
439 |
440 |
441 |
442 |
443 |
444 | -
445 |
446 |
-
447 |
448 |
449 |
450 | 12
451 | 75
452 | true
453 |
454 |
455 |
456 | Balance
457 |
458 |
459 |
460 | -
461 |
462 |
463 |
464 | 20
465 | 75
466 | true
467 | true
468 |
469 |
470 |
471 | background-color: rgb(255, 255, 255);
472 | color: rgb(234, 67, 53);
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 | -
486 |
487 |
488 | color: rgb(255, 0, 0);
489 |
490 |
491 | (+) status
492 |
493 |
494 |
495 |
496 |
497 |
498 | material_combo
499 | cost_spinbox
500 | quantity_spinbox
501 | cashpaid_spinbox
502 | reset_button
503 | dateTimeEdit
504 | totalstock_edit
505 | total_spinbox
506 | dealers_view
507 | deal_button
508 | toolButton
509 | dealer_edit
510 |
511 |
512 |
513 |
514 |
--------------------------------------------------------------------------------
/settingsdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "settingsdialog.h"
2 | #include "ui_settingsdialog.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | SettingsDialog::SettingsDialog(QSqlDatabase *database,
9 | QWidget *parent) :
10 | QDialog(parent),
11 | db(database),
12 | ui(new Ui::SettingsDialog)
13 | {
14 | ui->setupUi(this);
15 | initializeModels();
16 | setupModels();
17 | ui->tabWidget->setCurrentIndex(0);
18 | }
19 |
20 | void SettingsDialog::initializeModels()
21 | {
22 | user_model = new QSqlQueryModel(this);
23 | rawmaterial_model = new QSqlQueryModel(this);
24 | material_model = new QSqlQueryModel(this);
25 | employee_model = new QSqlQueryModel(this);
26 | }
27 |
28 | void SettingsDialog::setupModels()
29 | {
30 | setupUsersTabModel();
31 | setupRawMaterialsTabModel();
32 | setupMaterialsTabModel();
33 | setupEmployeesTabModel();
34 | }
35 |
36 | void SettingsDialog::setupUsersTabModel()
37 | {
38 | QSqlQuery q(*db);
39 | if(!q.exec("select * from users")){
40 | QSqlError err = q.lastError();
41 | QMessageBox::critical(this,"Error",err.text());
42 | }
43 |
44 | user_model->setQuery(q);
45 |
46 | ui->users_view->setModel(user_model);
47 | }
48 |
49 | void SettingsDialog::setupMaterialsTabModel()
50 | {
51 | QSqlQuery q(*db);
52 | if(!q.exec("select * from materials")){
53 | QSqlError err = q.lastError();
54 | QMessageBox::critical(this,"Error",err.text());
55 | }
56 |
57 | material_model->setQuery(q);
58 |
59 | ui->sellingmaterial_view->setModel(material_model);
60 | }
61 |
62 | void SettingsDialog::setupRawMaterialsTabModel()
63 | {
64 | QSqlQuery q(*db);
65 | if(!q.exec("select * from raw_materials")){
66 | QSqlError err = q.lastError();
67 | QMessageBox::critical(this,"Error",err.text());
68 | }
69 |
70 | rawmaterial_model->setQuery(q);
71 |
72 | ui->rawmaterials_view->setModel(rawmaterial_model);
73 | }
74 |
75 | void SettingsDialog::setupEmployeesTabModel()
76 | {
77 | qDebug() <<"setupEmployeesTabModel called";
78 | QSqlQuery q(*db);
79 | if(!q.exec("select name,rank from employees")){
80 | QSqlError err = q.lastError();
81 | QMessageBox::critical(this,"Error",err.text());
82 | }
83 | employee_model->setQuery(q);
84 | ui->employees_tableview->setModel(employee_model);
85 | }
86 |
87 | bool SettingsDialog::doesRawMaterialExists(const QString &material)
88 | {
89 | QSqlQuery q(*db);
90 | q.prepare("select * from raw_materials where type=?");
91 | q.bindValue(0,material);
92 | if(!q.exec()){
93 | QSqlError err = q.lastError();
94 | QMessageBox::warning(this,"Error","Coudn't check raw materials"
95 | "due to error : "+err.text());
96 | return true;
97 | }
98 | if(q.next())
99 | return true;
100 | return false;
101 | }
102 |
103 | bool SettingsDialog::doesUserExists(const QString &username)
104 | {
105 | QSqlQuery q(*db);
106 | q.prepare("select * from users where username=?");
107 | q.bindValue(0,username);
108 | if(!q.exec()){
109 | QSqlError err = q.lastError();
110 | QMessageBox::warning(this,"Error","Coudn't check users"
111 | "due to error : "+err.text());
112 | return true;
113 | }
114 | if(q.next())
115 | return true;
116 | return false;
117 | }
118 |
119 | bool SettingsDialog::doesSellingMaterialExists(const QString &material)
120 | {
121 | QSqlQuery q(*db);
122 | q.prepare("select * from materials where type=?");
123 | q.bindValue(0,material);
124 | if(!q.exec()){
125 | QSqlError err = q.lastError();
126 | QMessageBox::warning(this,"Error","Coudn't check materials"
127 | "due to error : "+err.text());
128 | return true;
129 | }
130 | if(q.next())
131 | return true;
132 | return false;
133 | }
134 |
135 | bool SettingsDialog::doesEmployeeExists(const QString &employee)
136 | {
137 | QSqlQuery q(*db);
138 | q.prepare("select * from employees where name=?");
139 | q.bindValue(0,employee);
140 | if(!q.exec()){
141 | QSqlError err = q.lastError();
142 | QMessageBox::warning(this,"Error","Coudn't check employees"
143 | "due to error : "+err.text());
144 | return true;
145 | }
146 | if(q.next())
147 | return true;
148 | return false;
149 | }
150 |
151 | SettingsDialog::~SettingsDialog()
152 | {
153 | delete ui;
154 | }
155 |
156 | void SettingsDialog::on_tabWidget_tabBarClicked(int index)
157 | {
158 | Q_UNUSED(index);
159 |
160 | setupModels();
161 | }
162 |
163 | void SettingsDialog::on_addrawmaterial_button_clicked()
164 | {
165 | ///check if the user has provided the right information
166 | // check for empty field
167 | if(ui->newrawmaterialtype_edit->text().isEmpty()){
168 | QMessageBox::warning(this,"No Type","Kindly fill in the type field");
169 | return;
170 | }
171 | //check if the material already exists
172 | if(doesRawMaterialExists(ui->newrawmaterialtype_edit->text())){
173 | QMessageBox::warning(this,"Exists","The material already exists in the list");
174 | return;
175 | }
176 | ///prepare the query
177 |
178 | QSqlQuery q(*db);
179 | q.prepare("insert into raw_materials (type,quantity) values(:type,:quantity)");
180 | q.bindValue(":type",ui->newrawmaterialtype_edit->text());
181 | q.bindValue(":quantity",ui->newrawmaterialspinBoxedit->value());
182 |
183 | //execute the query
184 | if(!q.exec()){
185 | QSqlError err = q.lastError();
186 | QMessageBox::critical(this,"Error",err.text());
187 | return;
188 | }
189 | setupRawMaterialsTabModel();
190 | ui->newrawmaterialtype_edit->clear();
191 | ui->newrawmaterialspinBoxedit->clear();
192 | }
193 |
194 | void SettingsDialog::on_adduser_button_clicked()
195 | {
196 | ///check if the user has provided the right information
197 | // check for empty field
198 | if(ui->newusername_edit->text().isEmpty()){
199 | QMessageBox::warning(this,"Empty Fields","Kindly fill in the type field");
200 | return;
201 | }
202 | //check if the material already exists
203 | if(doesUserExists(ui->newusername_edit->text())){
204 | QMessageBox::warning(this,"Exists","The user already exists in the list");
205 | return;
206 | }
207 | ///prepare the query
208 |
209 | QSqlQuery q(*db);
210 | q.prepare("insert into users (username,password) values(:name,:pass)");
211 | q.bindValue(":name",ui->newusername_edit->text());
212 | q.bindValue(":pass",ui->newpassword_edit->text());
213 |
214 | //execute the query
215 | if(!q.exec()){
216 | QSqlError err = q.lastError();
217 | QMessageBox::critical(this,"Error",err.text());
218 | return;
219 | }
220 | setupUsersTabModel();
221 | ui->newusername_edit->clear();
222 | }
223 |
224 |
225 | void SettingsDialog::on_addsellingmaterial_button_clicked()
226 | {
227 | ///check if the user has provided the right information
228 | // check for empty field
229 | if(ui->newsellingmaterialtype_edit->text().isEmpty()){
230 | QMessageBox::warning(this,"No Type","Kindly fill in the type field");
231 | return;
232 | }
233 | //check if the material already exists
234 | if(doesSellingMaterialExists(ui->newsellingmaterialtype_edit->text())){
235 | QMessageBox::warning(this,"Exists","The material already exists in the list");
236 | return;
237 | }
238 | ///prepare the query
239 |
240 | QSqlQuery q(*db);
241 | q.prepare("insert into materials (type,quantity) values(:type,:quantity)");
242 | q.bindValue(":type",ui->newsellingmaterialtype_edit->text());
243 | q.bindValue(":quantity",ui->newsellingmaterialspinBoxedit_2->value());
244 |
245 | //execute the query
246 | if(!q.exec()){
247 | QSqlError err = q.lastError();
248 | QMessageBox::critical(this,"Error",err.text());
249 | return;
250 | }
251 | setupMaterialsTabModel();
252 | ui->newsellingmaterialtype_edit->clear();
253 | ui->newsellingmaterialspinBoxedit_2->clear();
254 | }
255 |
256 | void SettingsDialog::on_addemployee_pushbutton_clicked()
257 | {
258 | ///check if the user has provided the right information
259 | // check for empty field
260 | if(ui->newemployeename_edit->text().isEmpty()){
261 | QMessageBox::warning(this,"Empty Fields","Kindly fill in the name field");
262 | return;
263 | }
264 | //check if the employee already exists
265 | if(doesEmployeeExists(ui->newemployeename_edit->text())){
266 | QMessageBox::warning(this,"Exists","The employee already exists in the list");
267 | return;
268 | }
269 | ///prepare the query
270 |
271 | QSqlQuery q(*db);
272 | q.prepare("insert into employees (name,rank) values(:name,:rank)");
273 | q.bindValue(":name",ui->newemployeename_edit->text());
274 | q.bindValue(":rank","Machine Man");
275 |
276 | //execute the query
277 | if(!q.exec()){
278 | QSqlError err = q.lastError();
279 | QMessageBox::critical(this,"Error",err.text());
280 | return;
281 | }
282 | setupEmployeesTabModel();
283 | ui->newemployeename_edit->clear();
284 | }
285 |
--------------------------------------------------------------------------------
/settingsdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGSDIALOG_H
2 | #define SETTINGSDIALOG_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class SettingsDialog;
9 | }
10 |
11 | class SettingsDialog : public QDialog
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit SettingsDialog(QSqlDatabase *db, QWidget *parent = 0);
17 | void initializeModels();
18 | void setupModels();
19 | void setupUsersTabModel();
20 | void setupMaterialsTabModel();
21 | void setupRawMaterialsTabModel();
22 | void setupEmployeesTabModel();
23 | bool doesRawMaterialExists(const QString &material);
24 | bool doesUserExists(const QString &username);
25 | bool doesSellingMaterialExists(const QString &material);
26 | bool doesEmployeeExists(const QString &employee);
27 | ~SettingsDialog();
28 |
29 | private slots:
30 | void on_tabWidget_tabBarClicked(int index);
31 | void on_addrawmaterial_button_clicked();
32 | void on_adduser_button_clicked();
33 | void on_addsellingmaterial_button_clicked();
34 |
35 | void on_addemployee_pushbutton_clicked();
36 |
37 | private:
38 | Ui::SettingsDialog *ui;
39 | QSqlQueryModel *user_model;
40 | QSqlQueryModel *rawmaterial_model;
41 | QSqlQueryModel *material_model;
42 | QSqlQueryModel *employee_model;
43 | QSqlDatabase *db;
44 | };
45 |
46 | #endif // SETTINGSDIALOG_H
47 |
--------------------------------------------------------------------------------
/settingsdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | SettingsDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 484
10 | 302
11 |
12 |
13 |
14 | Settings
15 |
16 |
17 | -
18 |
19 |
20 | 2
21 |
22 |
23 |
24 | Users
25 |
26 |
27 |
-
28 |
29 |
30 | QAbstractItemView::SingleSelection
31 |
32 |
33 | QAbstractItemView::SelectItems
34 |
35 |
36 |
37 | -
38 |
39 |
-
40 |
41 |
-
42 |
43 |
-
44 |
45 |
-
46 |
47 |
48 |
49 | 10
50 | 75
51 | true
52 |
53 |
54 |
55 | Name:
56 |
57 |
58 |
59 | -
60 |
61 |
62 |
63 | 10
64 | 75
65 | true
66 |
67 |
68 |
69 | Password:
70 |
71 |
72 |
73 |
74 |
75 | -
76 |
77 |
-
78 |
79 |
80 | -
81 |
82 |
83 |
84 |
85 |
86 |
87 | -
88 |
89 |
-
90 |
91 |
92 | Add User
93 |
94 |
95 |
96 | -
97 |
98 |
99 | Qt::Horizontal
100 |
101 |
102 |
103 | 40
104 | 20
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | -
114 |
115 |
116 | Qt::Vertical
117 |
118 |
119 |
120 | 20
121 | 40
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | Raw_Materials
133 |
134 |
135 | -
136 |
137 |
-
138 |
139 |
140 | -
141 |
142 |
-
143 |
144 |
-
145 |
146 |
-
147 |
148 |
149 |
150 | 10
151 | 75
152 | true
153 |
154 |
155 |
156 | Type:
157 |
158 |
159 |
160 | -
161 |
162 |
163 |
164 |
165 | -
166 |
167 |
-
168 |
169 |
170 |
171 | 10
172 | 75
173 | true
174 |
175 |
176 |
177 | Stock:
178 |
179 |
180 |
181 | -
182 |
183 |
184 |
185 | 12
186 |
187 |
188 |
189 | 999999999
190 |
191 |
192 |
193 |
194 |
195 | -
196 |
197 |
-
198 |
199 |
200 | Add Material
201 |
202 |
203 |
204 | -
205 |
206 |
207 | Qt::Horizontal
208 |
209 |
210 |
211 | 40
212 | 20
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 | -
222 |
223 |
224 | Qt::Vertical
225 |
226 |
227 |
228 | 20
229 | 40
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | -
239 |
240 |
241 |
242 | 12
243 | 75
244 | true
245 | true
246 |
247 |
248 |
249 | color: rgb(255, 0, 0);
250 | background-color: rgb(255, 255, 255);
251 |
252 |
253 | Note: No material names should match!!!!!!
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 | Selling Materials
262 |
263 |
264 | -
265 |
266 |
-
267 |
268 |
269 | -
270 |
271 |
-
272 |
273 |
-
274 |
275 |
276 |
277 | 10
278 | 75
279 | true
280 |
281 |
282 |
283 | Type:
284 |
285 |
286 |
287 | -
288 |
289 |
290 |
291 |
292 | -
293 |
294 |
-
295 |
296 |
297 |
298 | 10
299 | 75
300 | true
301 |
302 |
303 |
304 | Stock
305 |
306 |
307 |
308 | -
309 |
310 |
311 |
312 | 12
313 |
314 |
315 |
316 | 999999999
317 |
318 |
319 |
320 |
321 |
322 | -
323 |
324 |
-
325 |
326 |
-
327 |
328 |
329 | Add Material
330 |
331 |
332 |
333 | -
334 |
335 |
336 | Qt::Vertical
337 |
338 |
339 |
340 | 20
341 | 40
342 |
343 |
344 |
345 |
346 |
347 |
348 | -
349 |
350 |
351 | Qt::Horizontal
352 |
353 |
354 |
355 | 40
356 | 20
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 | -
368 |
369 |
370 |
371 | 12
372 | 75
373 | true
374 | true
375 |
376 |
377 |
378 | color: rgb(255, 0, 0);
379 | background-color: rgb(255, 255, 255);
380 |
381 |
382 | Note: No material names should match!!!!!!
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 | Employees
391 |
392 |
393 | -
394 |
395 |
396 | QAbstractItemView::SingleSelection
397 |
398 |
399 | QAbstractItemView::SelectItems
400 |
401 |
402 |
403 | -
404 |
405 |
-
406 |
407 |
-
408 |
409 |
-
410 |
411 |
412 |
413 | 10
414 | 75
415 | true
416 |
417 |
418 |
419 | Name:
420 |
421 |
422 |
423 | -
424 |
425 |
426 |
427 |
428 | -
429 |
430 |
-
431 |
432 |
433 | Add Employee
434 |
435 |
436 |
437 | -
438 |
439 |
440 | Qt::Horizontal
441 |
442 |
443 |
444 | 17
445 | 17
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 | -
455 |
456 |
457 | Qt::Vertical
458 |
459 |
460 |
461 | 20
462 | 40
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
--------------------------------------------------------------------------------
/stockmodel.cpp:
--------------------------------------------------------------------------------
1 | #include "stockmodel.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | StockModel::StockModel(QObject *parent, int quantitycolumn,
8 | qint64 lowerlimit) :
9 | QSqlQueryModel(parent),
10 | _col(quantitycolumn),
11 | _lowerlimit(lowerlimit)
12 | {
13 |
14 | }
15 |
16 | qint64 StockModel::lowerlimit() const
17 | {
18 | return _lowerlimit;
19 | }
20 |
21 | void StockModel::setLowerlimit(const qint64 &lowerlimit)
22 | {
23 | _lowerlimit = lowerlimit;
24 | }
25 |
26 | QVariant StockModel::data(const QModelIndex &index, int role) const
27 | {
28 | if(index.isValid() && index.column()==_col &&
29 | role==Qt::ForegroundRole){
30 | if(index.data().toLongLong() < _lowerlimit){
31 | QColor text;
32 | text.setNamedColor("#ea4335");//google red
33 | return QBrush(text);
34 | }else{
35 | QColor text;
36 | text.setNamedColor("#34a853");//google greeen
37 | return QBrush(text);
38 | }
39 | }
40 | //font
41 | if(index.isValid() && role==Qt::FontRole){
42 | return QFont("times",12,QFont::DemiBold);
43 | }
44 | //other colors of text
45 | if(index.isValid() && index.column()!=_col &&
46 | role==Qt::ForegroundRole){
47 | QColor text;
48 | text.setNamedColor("#4285f4");//google blue
49 | return QBrush(text);
50 | }
51 | return QSqlQueryModel::data(index,role);
52 | }
53 |
--------------------------------------------------------------------------------
/stockmodel.h:
--------------------------------------------------------------------------------
1 | #ifndef STOCKMODEL_H
2 | #define STOCKMODEL_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | class StockModel : public QSqlQueryModel
9 | {
10 | Q_OBJECT
11 | public:
12 | explicit StockModel(QObject *parent,int quantitycolumn=0,
13 | qint64 lowerlimit=100);
14 |
15 |
16 | qint64 lowerlimit() const;
17 | void setLowerlimit(const qint64 &lowerlimit);
18 |
19 | protected:
20 | QVariant data(const QModelIndex &index, int role) const;
21 |
22 | private:
23 | qint64 _lowerlimit;
24 | int _col;
25 | };
26 |
27 | #endif // STOCKMODEL_H
28 |
--------------------------------------------------------------------------------
/tableprinter.cpp:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (c) 2016, Anton Onishchenko
4 | ** All rights reserved.
5 | **
6 | ** Redistribution and use in source and binary forms, with or without modification,
7 | ** are permitted provided that the following conditions are met:
8 | **
9 | ** 1. Redistributions of source code must retain the above copyright notice, this
10 | ** list of conditions and the following disclaimer.
11 | **
12 | ** 2. Redistributions in binary form must reproduce the above copyright notice, this
13 | ** list of conditions and the following disclaimer in the documentation and/or other
14 | ** materials provided with the distribution.
15 | **
16 | ** 3. Neither the name of the copyright holder nor the names of its contributors may
17 | ** be used to endorse or promote products derived from this software without
18 | ** specific prior written permission.
19 | **
20 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24 | ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 | ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | **
31 | ****************************************************************************/
32 |
33 | #include "tableprinter.h"
34 |
35 | #include
36 | #include
37 | #include
38 |
39 | TablePrinter::TablePrinter(QPainter* painter, QPrinter* printer) :
40 | painter(painter),
41 | printer(printer) {
42 | topMargin = 5;
43 | bottomMargin = 5;
44 | leftMargin = 10;
45 | rightMargin = 5;
46 | headerHeight = 0;
47 | bottomHeight = 0;
48 | leftBlank = 0;
49 | rightBlank = 0;
50 | maxRowHeight = 1000;
51 | pen = painter->pen();
52 | headersFont = painter->font();
53 | contentFont = painter->font();
54 | headerColor = painter->pen().color();
55 | contentColor = painter->pen().color();
56 | prepare = NULL;
57 | error = "No error";
58 | }
59 |
60 | bool TablePrinter::printTable(const QAbstractItemModel* model, const QVector columnStretch,
61 | const QVector headers) {
62 |
63 | //--------------------------------- error checking -------------------------------------
64 |
65 | int columnCount = model->columnCount();
66 | int count = columnStretch.count();
67 | if(count != columnCount) {
68 | error = "Different columns count in model and in columnStretch";
69 | return false;
70 | }
71 | count = headers.count();
72 | if(count != columnCount && count != 0) {
73 | error = "Different columns count in model and in headers";
74 | return false;
75 | }
76 | if(!printer->isValid()) {
77 | error = "printer.isValid() == false";
78 | return false;
79 | }
80 | if(!painter->isActive()) {
81 | error = "painter.isActive() == false";
82 | return false;
83 | }
84 | double tableWidth = painter->viewport().width() - leftBlank - rightBlank;
85 | if(tableWidth <= 0) {
86 | error = "wrong table width";
87 | return false;
88 | }
89 | int totalStretch = 0;
90 | for (int i = 0; i < columnStretch.count(); i++) {
91 | if(columnStretch[i] < 0) {
92 | error = QString("wrong column stretch, columnt: %1 stretch: %2").arg(i).arg(columnStretch[i]);
93 | return false;
94 | }
95 | totalStretch += columnStretch[i];
96 | }
97 | if(totalStretch <= 0) {
98 | error = QString("wrong stretch");
99 | return false;
100 | }
101 | QVector columnWidth;
102 | for (int i = 0; i < columnStretch.count(); i++) {
103 | columnWidth.append(tableWidth / totalStretch * columnStretch[i]);
104 | }
105 | int initValue;
106 | headers.isEmpty() ? initValue = 0 : initValue = -1;
107 |
108 | //----------------------------------------------------------------------------
109 |
110 | painter->save(); // before table print
111 |
112 | // to know row height before printing
113 | // at first print to test image
114 | QPainter testSize;
115 | QImage* image = new QImage(10, 10, QImage::Format_RGB32);
116 | image->setDotsPerMeterX(printer->logicalDpiX() * 100 / 2.54); // 2.54 cm = 1 inch
117 | image->setDotsPerMeterY(printer->logicalDpiY() * 100 / 2.54);
118 | testSize.begin(image);
119 |
120 | if(prepare) {
121 | painter->save();
122 | painter->translate(-painter->transform().dx(), -painter->transform().dy());
123 | prepare->preparePage(painter);
124 | painter->restore();
125 | }
126 |
127 | painter->setPen(pen);
128 | painter->setFont(contentFont);
129 | testSize.setFont(contentFont);
130 | painter->translate(-painter->transform().dx() + leftBlank, 0);
131 | painter->save();
132 | painter->setFont(headersFont);
133 | testSize.setFont(headersFont);
134 | painter->drawLine(0, 0, tableWidth, 0); // first horizontal line
135 | for(int j = initValue; j < model->rowCount(); j++) { // for each row
136 | if(j == 0) {
137 | painter->setFont(contentFont);
138 | testSize.setFont(contentFont);
139 | }
140 |
141 | // --------------------------- row height counting ----------------------------
142 |
143 | int maxHeight = 0; // max row Height
144 | for(int i = 0; i < columnCount; i++) { // for each column
145 | QString str;
146 | if(j >= 0) {
147 | str = model->data(model->index(j,i), Qt::DisplayRole).toString();
148 | } else {
149 | str = headers.at(i);
150 | }
151 | QRect rect(0, 0, columnWidth[i] - rightMargin - leftMargin, maxRowHeight);
152 | QRect realRect;
153 | testSize.drawText(rect, Qt::AlignLeft | Qt::TextWordWrap, str, &realRect);
154 | if (realRect.height() > maxHeight && columnStretch[i] != 0) {
155 | realRect.height() > maxRowHeight ? maxHeight = maxRowHeight : maxHeight = realRect.height();
156 | }
157 | }
158 |
159 | if(painter->transform().dy() + maxHeight + topMargin + bottomMargin > painter->viewport().height() -
160 | bottomHeight) { // begin from new page
161 | int y = painter->transform().dy();
162 | painter->restore();
163 | painter->save();
164 | for(int i = 0; i < columnCount; i++) { // vertical lines
165 | painter->drawLine(0, 0, 0,
166 | - painter->transform().dy() + y);
167 | painter->translate(columnWidth[i], 0);
168 | }
169 | painter->drawLine(0, 0, 0, - painter->transform().dy() + y); // last vertical line
170 | painter->restore();
171 | printer->newPage();
172 | if(prepare) {
173 | painter->save();
174 | painter->translate(-painter->transform().dx(), -painter->transform().dy());
175 | prepare->preparePage(painter);
176 | painter->restore();
177 | }
178 | painter->translate(-painter->transform().dx() + leftBlank, -painter->transform().dy() + headerHeight);
179 | painter->save();
180 | painter->drawLine(0, 0, tableWidth,
181 | 0); // first horizontal line
182 | }
183 |
184 | //------------------------------ content printing -------------------------------------------
185 |
186 | painter->save();
187 | j >= 0 ? painter->setPen(QPen(contentColor)) : painter->setPen(QPen(headerColor));
188 | for(int i = 0; i < columnCount; i++) { // for each column
189 | QString str;
190 | if(j >= 0) {
191 | str = model->data(model->index(j,i), Qt::DisplayRole).toString();
192 | } else {
193 | str = headers.at(i);
194 | }
195 | QRect rec(leftMargin, topMargin, columnWidth[i] - rightMargin - leftMargin, maxHeight);
196 | painter->drawText(rec, Qt::AlignLeft | Qt::TextWordWrap, str);
197 | painter->translate(columnWidth[i], 0);
198 | }
199 | painter->restore();
200 |
201 | painter->drawLine(0, maxHeight + topMargin + bottomMargin, tableWidth,
202 | maxHeight + topMargin + bottomMargin); // last horizontal line
203 | painter->translate(0, maxHeight + topMargin + bottomMargin);
204 | }
205 | int y = painter->transform().dy();
206 | painter->restore();
207 | painter->save();
208 | for(int i = 0; i < columnCount; i++) { // vertical lines
209 | painter->drawLine(0, 0, 0,
210 | - painter->transform().dy() + y);
211 | painter->translate(columnWidth[i], 0);
212 | }
213 | painter->drawLine(0, 0, 0, - painter->transform().dy() + y); // last vertical line
214 | painter->restore();
215 |
216 | testSize.end();
217 | delete image;
218 |
219 | painter->restore(); // before table print
220 |
221 | return true;
222 | }
223 |
224 | QString TablePrinter::lastError() {
225 | return error;
226 | }
227 |
228 | void TablePrinter::setCellMargin(int left, int right, int top, int bottom) {
229 | topMargin = top;
230 | bottomMargin = bottom;
231 | leftMargin = left;
232 | rightMargin = right;
233 | }
234 |
235 | void TablePrinter::setPageMargin(int left, int right, int top, int bottom) {
236 | headerHeight = top;
237 | bottomHeight = bottom;
238 | leftBlank = left;
239 | rightBlank = right;
240 | }
241 |
242 | void TablePrinter::setPagePrepare(PagePrepare *prep) {
243 | prepare = prep;
244 | }
245 |
246 | void TablePrinter::setPen(QPen p) {
247 | pen = p;
248 | }
249 |
250 | void TablePrinter::setHeadersFont(QFont f) {
251 | headersFont = f;
252 | }
253 |
254 | void TablePrinter::setContentFont(QFont f) {
255 | contentFont = f;
256 | }
257 |
258 | void TablePrinter::setHeaderColor(QColor color) {
259 | headerColor = color;
260 | }
261 |
262 | void TablePrinter::setContentColor(QColor color) {
263 | contentColor = color;
264 | }
265 |
266 | void TablePrinter::setMaxRowHeight(int height) {
267 | maxRowHeight = height;
268 | }
269 |
--------------------------------------------------------------------------------
/tableprinter.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | **
3 | ** Copyright (c) 2016, Anton Onishchenko
4 | ** All rights reserved.
5 | **
6 | ** Redistribution and use in source and binary forms, with or without modification,
7 | ** are permitted provided that the following conditions are met:
8 | **
9 | ** 1. Redistributions of source code must retain the above copyright notice, this
10 | ** list of conditions and the following disclaimer.
11 | **
12 | ** 2. Redistributions in binary form must reproduce the above copyright notice, this
13 | ** list of conditions and the following disclaimer in the documentation and/or other
14 | ** materials provided with the distribution.
15 | **
16 | ** 3. Neither the name of the copyright holder nor the names of its contributors may
17 | ** be used to endorse or promote products derived from this software without
18 | ** specific prior written permission.
19 | **
20 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24 | ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 | ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | **
31 | ****************************************************************************/
32 |
33 | #ifndef TABLEPRINTER_H
34 | #define TABLEPRINTER_H
35 |
36 | #include
37 | #include
38 |
39 | class QPrinter;
40 | class QPainter;
41 | class QAbstractItemModel;
42 |
43 | /**
44 | * @brief The PagePrepare Abstract class - base class for
45 | * classes that will print something like headers, borders...
46 | * on each page with table
47 | */
48 | class PagePrepare {
49 | public:
50 | virtual void preparePage(QPainter *painter) = 0;
51 | virtual ~PagePrepare() {}
52 | };
53 |
54 | class TablePrinter
55 | {
56 | public:
57 | TablePrinter(QPainter *painter, QPrinter *printer);
58 | bool printTable(const QAbstractItemModel* model, const QVector columnStretch, const QVector headers = QVector());
59 | QString lastError();
60 | void setCellMargin(int left = 10, int right = 5, int top = 5, int bottom = 5);
61 | void setPageMargin(int left = 50, int right = 20, int top = 20, int bottom = 20);
62 | void setPagePrepare(PagePrepare *prepare);
63 | void setPen(QPen pen); // for table borders
64 | void setHeadersFont(QFont font);
65 | void setContentFont(QFont font);
66 | void setHeaderColor(QColor color);
67 | void setContentColor(QColor color);
68 | void setMaxRowHeight(int height);
69 | private:
70 | QPainter *painter;
71 | QPrinter *printer;
72 | PagePrepare *prepare;
73 | QPen pen; // for table borders
74 | QFont headersFont;
75 | QFont contentFont;
76 | QFont titleFont;
77 | QColor headerColor;
78 | QColor contentColor;
79 | // cell margins
80 | int topMargin;
81 | int bottomMargin;
82 | int leftMargin;
83 | int rightMargin;
84 |
85 | // margins for table
86 | int headerHeight;
87 | int bottomHeight;
88 | int leftBlank;
89 | int rightBlank;
90 |
91 | int maxRowHeight;
92 |
93 | QString error;
94 | };
95 |
96 | #endif // TABLEPRINTER_H
97 |
--------------------------------------------------------------------------------