diff --git a/admin/mainwindow.cpp b/admin/mainwindow.cpp index d6d51612474ae103865b180388e06258d96a4106..3c4428de54165763364eb33103127ae60578181d 100644 --- a/admin/mainwindow.cpp +++ b/admin/mainwindow.cpp @@ -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 +} diff --git a/admin/mainwindow.h b/admin/mainwindow.h index affa1fcd337e07fb10a0b80ef8b6789af0384624..11b1f52ebca92ca983ef6cb0f97ea20589559034 100644 --- a/admin/mainwindow.h +++ b/admin/mainwindow.h @@ -79,6 +79,8 @@ private slots: void on_moneyDiffReload_clicked(); + void on_accTransferSubmit_clicked(); + private: Ui::MainWindow *ui; QSqlTableModel* model; diff --git a/admin/mainwindow.ui b/admin/mainwindow.ui index 36132278a83458e5ab67b290151029a8f7a6d116..eefb222d4f8e241d85493e97b675d350ada6fcb8 100644 --- a/admin/mainwindow.ui +++ b/admin/mainwindow.ui @@ -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>