Commit f5b36244 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Add GUI for money, remove some old code and GUI.

Contains an almost finished GUI (for the money accounts), which probably
won't change. Along with code to popuplate the combo boxes, and the
account list.

Introduces a new view in the DB.
parent 58e3f544
......@@ -312,12 +312,36 @@ MainWindow::MainWindow(QWidget *parent) :
// ==================================================
QIntValidator* pIntVal = new QIntValidator(0, INT_MAX);
ui->moneyMoveAmount->setValidator(pIntVal);
ui->addMoneyEdit->setValidator(pIntVal);
updateMoneyString();
setStockValues();
// QIntValidator* pIntVal = new QIntValidator(0, INT_MAX);
// ui->moneyMoveAmount->setValidator(pIntVal);
// ui->addMoneyEdit->setValidator(pIntVal);
// updateMoneyString();
QSqlTableModel* accModel = new QSqlTableModel();
ui->accTreeView->setModel(accModel);
accModel->setTable("money_simple");
accModel->select();
accModel->setHeaderData(0, Qt::Horizontal, "Namn");
accModel->setHeaderData(1, Qt::Horizontal, "Kronor");
accModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
QSqlRecord rec = accModel->record();
rec.setValue("name", QVariant("Lager (projicerat)"));
rec.setValue("amount", QVariant(QString("%1").arg(get_projected_stock_value().toDouble() / 100.0,
0, 'f', 2)));
accModel->insertRecord(-1, rec);
rec.setValue("name", QVariant("Lager (inköp)"));
rec.setValue("amount", QVariant(QString("%1").arg(get_acquistion_stock_value().toDouble() / 100.0,
0, 'f', 2)));
accModel->insertRecord(-1, rec);
QSqlQuery accQuery("SELECT id, name FROM money");
while (accQuery.next()) {
ui->accTransferFrom->addItem(accQuery.value(1).toString(), accQuery.value(0));
ui->accTransferTo->addItem(accQuery.value(1).toString(), accQuery.value(0));
}
}
MainWindow::~MainWindow()
......@@ -325,6 +349,11 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::updateMoneyString()
{
qDebug () << "Updating Money Strings";
}
/*
* This updates the QSqlTableModel to contain the same data as the database.
* This is needed since it looks at a view, and can therefore not find the
......@@ -480,39 +509,6 @@ void MainWindow::on_buyRemoveButton_clicked()
tempAcquisitionsModel->select();
}
void MainWindow::updateMoneyString()
{
QSqlQuery query("SELECT name, amount / 100.0 "
"FROM money "
"WHERE name in ('Cash Drawer', 'Vault') "
"ORDER BY name ASC");
// TODO also push the names from db to gui
query.next();
ui->drawerLabel->setText(QString("%1").arg(query.value(1).toDouble(), 0, 'f', 2));
query.next();
ui->vaultLabel->setText (QString("%1").arg(query.value(1).toDouble(), 0, 'f', 2));
}
void MainWindow::on_toVaultButton_clicked()
{
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(from, to, amount);
ui->moneyMoveAmount->setText("");
updateMoneyString();
}
void MainWindow::transferMoney(QString from, QString to, int amount, QString message)
{
if ((from == "" && to == "") || amount == 0)
......@@ -545,28 +541,6 @@ void MainWindow::transferMoney(QString from, QString to, int amount)
transferMoney(from, to, amount, NULL);
}
void MainWindow::on_addMoneySubmitButton_clicked()
{
addRemoveCommon(CASH_NULL, CASH_ACCOUNT);
}
void MainWindow::on_removeMoneySubmitButton_clicked()
{
addRemoveCommon(CASH_ACCOUNT, CASH_NULL);
}
void MainWindow::addRemoveCommon(QString from, QString to)
{
QString msg = ui->addMoneyReason->toPlainText();
QString message = msg == "" ? NULL : msg;
int amount = ui->addMoneyEdit->text().toInt();
transferMoney(from, to, amount, message);
ui->addMoneyEdit->setText("");
ui->addMoneyReason->setPlainText("");
updateMoneyString();
}
void MainWindow::on_addDrainageButton_clicked()
{
// Products to go from crown to öre
......@@ -798,7 +772,7 @@ QVariant MainWindow::get_acquistion_stock_value()
"FROM stock s INNER JOIN products p "
"ON s.product_id = p.id");
while (tQuery.next()) {
qDebug() << __LINE__;
// qDebug() << __LINE__;
long target = tQuery.value("active").toLongLong();
if (target < 0) continue;
......@@ -815,7 +789,7 @@ QVariant MainWindow::get_acquistion_stock_value()
while (query.next()) {
long sub_amount = query.value("amount").toLongLong();
long item_price = query.value("item_price").toLongLong();
qDebug() << __LINE__ << amount << sub_amount;
// qDebug() << __LINE__ << amount << sub_amount;
if (amount + sub_amount > target) {
total_product_price += (target - amount) * item_price;
amount = target;
......@@ -843,15 +817,6 @@ QVariant MainWindow::get_projected_stock_value() {
}
void MainWindow::setStockValues()
{
double accVal = get_acquistion_stock_value().toDouble() / 100.0;
ui->valueAccquisitionLabel->setText(QString("%1").arg(accVal, 0, 'f', 2));
double projVal = get_projected_stock_value().toDouble() / 100.0;
ui->valueProjectedLabel->setText(QString("%1").arg(projVal, 0, 'f', 2));
}
void MainWindow::setProductFilter()
{
QString searchStr = ui->productListSearch->text();
......
......@@ -37,13 +37,13 @@ private slots:
void on_buyRemoveButton_clicked();
void on_toVaultButton_clicked();
// void on_toVaultButton_clicked();
void on_toDrawerButton_clicked();
// void on_toDrawerButton_clicked();
void on_addMoneySubmitButton_clicked();
// void on_addMoneySubmitButton_clicked();
void on_removeMoneySubmitButton_clicked();
// void on_removeMoneySubmitButton_clicked();
void on_addDrainageButton_clicked();
......
......@@ -689,276 +689,111 @@
<string>Övrigt</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="4" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_31">
<property name="text">
<string>Kassalåda</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Kassaskåp</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QLabel" name="vaultLabel">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Överför (öre)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="moneyMoveAmount">
<property name="placeholderText">
<string>0</string>
</property>
</widget>
<item row="0" column="1" rowspan="4">
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="accTransferAmonut">
<property name="maximum">
<double>99999999999999991433150857216.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLineEdit" name="accTransferText">
<property name="placeholderText">
<string>Notering (anledning, person, ...)</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="accTransferTo"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Från</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Kronor</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="accTransferFrom"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Till</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="accTransferSubmit">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1" colspan="3">
<widget class="QLabel" name="drawerLabel">
<property name="text">
<string>X</string>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="toVaultButton">
<property name="maximumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="toolTip">
<string>Cash Drawer to Vault</string>
<item>
<widget class="QTreeView" name="accTreeView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="text">
<string></string>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="toDrawerButton">
<property name="maximumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="toolTip">
<string>Vault to Cash Drawer</string>
</property>
<item>
<widget class="QPushButton" name="accNewAccBtn">
<property name="text">
<string></string>
<string>Lägg till konto</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="2">
<item row="1" column="3">
<widget class="QPushButton" name="openTillButton">
<property name="text">
<string>Öppna Kassan</string>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<property name="verticalSpacing">
<number>0</number>
<item row="0" column="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<item row="1" column="2">
<widget class="QPushButton" name="removeMoneySubmitButton">
<property name="text">
<string>Ta bort</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="addMoneySubmitButton">
<property name="text">
<string>Lägg till</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLineEdit" name="addMoneyEdit">
<property name="placeholderText">
<string>0</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Lägg till/ta bort pengar (öre)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QPlainTextEdit" name="addMoneyReason">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Anledning / Person / ...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="7" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Lagervärde:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>• inköp</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>• projicerat</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="valueAccquisitionLabel">
<property name="text">
<string>456.30</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="valueProjectedLabel">
<property name="text">
<string>852.20</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QPushButton" name="stockValueRefresh">
<property name="text">
<string>Uppdatera</string>
</property>
</widget>
</item>
</layout>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_7">
<item row="1" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
......
......@@ -216,6 +216,11 @@ INNER JOIN diff_help d ON p.id = d.product_id;
-- WHERE p.sale_status = 0 OR s.active != 0;
-- where p.sale_status in (0, 1);
CREATE VIEW money_simple AS
SELECT name,
printf("%.2f", amount / 100.0) AS amount
FROM money WHERE id != 0;
-- ============================== Triggers ===============================
-- some of these would benefit from being FOR EACH STATEMENT instead of
......
Markdown is supported
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