Commit 01a523df authored by Hugo Hörnquist's avatar Hugo Hörnquist

Readded money transfer functionality

parent f5b36244
......@@ -509,38 +509,6 @@ void MainWindow::on_buyRemoveButton_clicked()
tempAcquisitionsModel->select();
}
void MainWindow::transferMoney(QString from, QString to, int amount, QString message)
{
if ((from == "" && to == "") || amount == 0)
return;
QSqlQuery query;
query.prepare("INSERT INTO money_transfers (change, note, from_acc, to_acc) "
"VALUES (:amount, :message, "
"(SELECT CASE "
" WHEN count(1) != 0 THEN id "
" ELSE 0 END "
" FROM money WHERE name = :from), "
"(SELECT CASE "
" WHEN count(1) != 0 THEN id "
" ELSE 0 END "
" FROM money WHERE name = :to))");
query.bindValue(":amount", amount);
query.bindValue(":message", message);
query.bindValue(":from", from);
query.bindValue(":to", to);
if (!query.exec())
qDebug() << query.lastError();
open_till();
}
// invalid account names results in the outside world
void MainWindow::transferMoney(QString from, QString to, int amount)
{
transferMoney(from, to, amount, NULL);
}
void MainWindow::on_addDrainageButton_clicked()
{
// Products to go from crown to öre
......@@ -864,3 +832,32 @@ void MainWindow::on_moneyDiffReload_clicked()
ui->diffDrawer->setText("");
setMoneyDiffLabels();
}
void MainWindow::on_accTransferSubmit_clicked()
{
qlonglong amount = ui->accTransferAmonut->value() * 100;
qlonglong from = ui->accTransferFrom->currentData().toLongLong();
qlonglong to = ui->accTransferTo->currentData().toLongLong();
QString text = ui->accTransferText->text();
if (amount == 0 || from == to) return;
qDebug() << amount << from << to << text;
QSqlQuery query;
query.prepare("INSERT INTO money_transfers (change, from_acc, to_acc, note) "
"VALUES (:amount, :from, :to, :note)");
query.bindValue(":amount", amount);
query.bindValue(":from", from);
query.bindValue(":to", to);
query.bindValue(":note", text.isEmpty() ? QVariant::String : QVariant(text));
if (!query.exec())
qDebug() << query.lastError();
ui->accTransferAmonut->setValue(0);
ui->accTransferFrom->setCurrentIndex(0);
ui->accTransferTo->setCurrentIndex(0);
ui->accTransferText->setText("");
// TODO update money values
}
......@@ -79,6 +79,8 @@ private slots:
void on_moneyDiffReload_clicked();
void on_accTransferSubmit_clicked();
private:
Ui::MainWindow *ui;
QSqlTableModel* model;
......
......@@ -695,6 +695,9 @@
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="accTransferAmonut">
<property name="suffix">
<string> kr</string>
</property>
<property name="maximum">
<double>99999999999999991433150857216.000000000000000</double>
</property>
......
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