-
Notifications
You must be signed in to change notification settings - Fork 1
/
priprematransporta.cpp
77 lines (59 loc) · 2.48 KB
/
priprematransporta.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "priprematransporta.h"
#include "ui_priprematransporta.h"
#include <QMessageBox>
#include <QSqlQuery>
#include <QSqlError>
PripremaTransporta::PripremaTransporta(QWidget *parent) :
QDialog(parent),
ui(new Ui::PripremaTransporta)
{
ui->setupUi(this);
setModelStavke();
ui->btnpriprema->setEnabled(false);
}
PripremaTransporta::~PripremaTransporta()
{
delete ui;
}
void PripremaTransporta::setModelStavke()
{
QTreeView *view = ui->treeStavke;
modelStavke = new QSqlQueryModel();
modelStavke->setQuery("select stavka.id_stavke, ogranak.naziv, artikal.ime, sum(odobrena_kol), status, stavka.id_artikla from stavka join artikal on stavka.id_artikla=artikal.id_artikla join spisak on spisak.id_spiska = stavka.id_spiska join nalog on spisak.id_naloga=nalog.id join ogranak on nalog.id_ogranka= ogranak.id_ogranka where status= 'U_MAGACINU' group by artikal.ime");
view->setModel(modelStavke);
modelStavke->setHeaderData(1, Qt::Horizontal, "Ogranak");
modelStavke->setHeaderData(2, Qt::Horizontal, "Artikal");
modelStavke->setHeaderData(3, Qt::Horizontal, "Ukupna kolicina");
// view->setModel(modelStavke);
view->setColumnHidden(4, true);
view->setColumnHidden(0, true);
view->setColumnHidden(5, true);
view->setSortingEnabled(true);
selectionModel = ui->treeStavke->selectionModel();
connect(selectionModel,SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
}
void PripremaTransporta::updateSelection(const QItemSelection &selected,
const QItemSelection &deselected)
{
QModelIndex index;
QModelIndexList items = selected.indexes();
index = items.first();
_odabranaStavkaId = modelStavke->data(modelStavke->index(index.row(), 5)).toInt();
ui->btnpriprema->setEnabled(true);
}
void PripremaTransporta::on_btnpriprema_clicked()
{
QSqlQuery query;
query.prepare(QString("UPDATE stavka SET status ='U_TRANSPORTU' WHERE id_artikla='%1'").arg(_odabranaStavkaId));
if(!query.exec()){
QMessageBox::warning(this, "Transport stavke", "Greska prilikom transporta stavke.");
}
else{
setModelStavke();
pripremaTransport.append(_odabranaStavkaId);
}
}
void PripremaTransporta::on_pushButton_clicked()
{
this->close();
}