Commit d8173778 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

cash drawer opening and minor fixups

parent 39b62ba3
......@@ -32,3 +32,8 @@ HEADERS += mainwindow.h \
qsqltreeitem.h
FORMS += mainwindow.ui
unix|win32: LIBS += -L$$PWD/../bad_com/ -lcom
INCLUDEPATH += $$PWD/../bad_com
DEPENDPATH += $$PWD/../bad_com
......@@ -13,7 +13,7 @@ ComboBoxItemDelegate::ComboBoxItemDelegate(QObject* parent) : QStyledItemDelegat
ComboBoxItemDelegate::~ComboBoxItemDelegate() {}
// initialises initial data
QWidget* ComboBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
QWidget* ComboBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
{
QComboBox* cb = new QComboBox(parent);
for (int i = 0; i < 3; i++)
......@@ -40,7 +40,7 @@ void ComboBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *mod
}
// sets what's displayed when not in edit mode
QString ComboBoxItemDelegate::displayText(const QVariant &value, const QLocale &locale) const
QString ComboBoxItemDelegate::displayText(const QVariant &value, const QLocale& /*locale*/) const
{
return get_index_string(value.toInt());
}
......
......@@ -24,6 +24,8 @@
#include "qsqltreemodel.h"
#include "serial.h"
#define CASH_ACCOUNT "Cash Drawer"
#define VAULT_ACCOUNT "Vault"
......@@ -46,10 +48,14 @@
// TODO can't edit note, only replace content
// TODO other money transfers crown ammounts
// TODO money diff doesn't update when cash drawer changes elsewhere in program
// it however still inserts the correct data into the db
// This binds into most strings not auto updating, and some more needing manual updates
/*
* All internal prices should be in öre
* Never trust a front end number unless you KNOW it's good
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
......@@ -57,6 +63,11 @@ MainWindow::MainWindow(QWidget *parent) :
{
ui->setupUi(this);
setbuf(stdout, NULL);
// TODO TODO get name from somewhere
port_name = (char*) "com_port";
port_setup(port_name, 9600);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("stupan.db");
......@@ -294,7 +305,7 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::on_inventoryModel_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
void MainWindow::on_inventoryModel_dataChanged(const QModelIndex &topLeft, const QModelIndex& /*bottomRight*/, const QVector<int>& /*roles*/)
{
if (topLeft.column() != 3) return;
......@@ -444,6 +455,8 @@ void MainWindow::on_submitBuyButton_clicked()
tempAcquisitionsModel->select();
updateMoneyString();
((QSqlRelationalTableModel*) ui->stockView->model())->select();
open_till();
}
void MainWindow::on_buyRemoveButton_clicked()
......@@ -468,27 +481,25 @@ void MainWindow::updateMoneyString()
ui->vaultLabel->setText (QString("%1").arg(query.value(1).toDouble(), 0, 'f', 2));
}
// TODO generalize these two into one function
void MainWindow::on_toVaultButton_clicked()
{
int amount = ui->moneyMoveAmount->text().toInt();
transferMoney(CASH_ACCOUNT, VAULT_ACCOUNT, amount);
ui->moneyMoveAmount->setText("");
updateMoneyString();
toVaultDrawer_shared(CASH_ACCOUNT, VAULT_ACCOUNT);
}
void MainWindow::on_toDrawerButton_clicked()
{
toVaultDrawer_shared(VAULT_ACCOUNT, CASH_ACCOUNT);
}
void MainWindow::toVaultDrawer_shared(QString from, QString to)
{
int amount = ui->moneyMoveAmount->text().toInt();
transferMoney(VAULT_ACCOUNT, CASH_ACCOUNT, amount);
transferMoney(from, to, amount);
ui->moneyMoveAmount->setText("");
updateMoneyString();
}
// amount is in öre
// invalid account names results in the outside world
void MainWindow::transferMoney(QString from, QString to, int amount)
{
......@@ -511,6 +522,8 @@ void MainWindow::transferMoney(QString from, QString to, int amount)
query.bindValue(":to", to);
if (!query.exec())
qDebug() << query.lastError();
open_till();
}
......@@ -768,3 +781,13 @@ void MainWindow::setMoneyDiffLabels(int new_total)
double diff = new_total - setMoneyDiffLabels();
ui->diffTotal->setText(QString("%1 kr").arg(diff / 100.0, 0, 'f', 2));
}
void MainWindow::on_openTillButton_clicked()
{
open_till();
}
void MainWindow::open_till()
{
port_write(port_name, 1);
}
......@@ -79,11 +79,15 @@ private slots:
void on_submitStockDiff_clicked();
void on_openTillButton_clicked();
private:
Ui::MainWindow *ui;
QSqlTableModel* model;
DisablingModel* tempAcquisitionsModel;
char* port_name;
void setNoteAddSelect(const QString& search);
void updateMoneyString();
void setMoneyDiffLabels(int);
......@@ -92,7 +96,9 @@ private:
void updateDrainageView();
void updateCurrentDrainageStatus();
void set_productModel_dirty_helper();
void toVaultDrawer_shared(QString from, QString to);
void open_till();
};
#endif // MAINWINDOW_H
......@@ -21,7 +21,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>4</number>
<number>2</number>
</property>
<property name="tabsClosable">
<bool>false</bool>
......@@ -194,7 +194,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<widget class="QWidget" name="layoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableView" name="purchaseView"/>
......@@ -202,7 +202,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Totalt Inköpspris (kr):</string>
</property>
......@@ -338,7 +338,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout_1">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
......@@ -416,7 +416,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......@@ -735,7 +735,7 @@
<item row="3" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="label_31">
<property name="text">
<string>Cash Drawer</string>
</property>
......@@ -820,7 +820,7 @@
</layout>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="openTillButton">
<property name="text">
<string>Öppna Kassan</string>
</property>
......
......@@ -5,7 +5,7 @@
TextEditDelegate::TextEditDelegate(QObject* parent)
: QItemDelegate(parent) { }
QWidget* TextEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
QWidget* TextEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
{
QPlainTextEdit* editor = new QPlainTextEdit(parent);
editor->setTabChangesFocus(true);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment