From: Konrad Rosenbaum Date: Thu, 29 Dec 2011 14:44:30 +0000 (+0100) Subject: start for payment type support, so far very rudimentary X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=cf7412b357a9c37a4520f9ea82cca1d89748ca25;p=web%2Fkonrad%2Fsmoke.git start for payment type support, so far very rudimentary --- diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index 2f57877..52975ea 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -13,7 +13,8 @@ HEADERS += \ dialogs/wizard.h \ dialogs/orderauditdlg.h \ dialogs/orderauditdlg_p.h \ - dialogs/backupdlg.h + dialogs/backupdlg.h \ + dialogs/payedit.h SOURCES += \ dialogs/configdialog.cpp \ @@ -29,7 +30,8 @@ SOURCES += \ dialogs/flagedit.cpp \ dialogs/wizard.cpp \ dialogs/orderauditdlg.cpp \ - dialogs/backupdlg.cpp + dialogs/backupdlg.cpp \ + dialogs/payedit.cpp RESOURCES += dialogs/dialogfiles.qrc diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index d9cd83e..fe45e70 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -706,7 +706,7 @@ void MOrderWindow::payment() if(!ok)return; if(pay<=0)return; //submit - MTOrderPay op=req->queryOrderPay(m_order.orderid(),pay); + MTOrderPay op=req->queryOrderPay(m_order.orderid(),pay,"",""); if(op.hasError()){ QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(op.errorString())); return; diff --git a/src/dialogs/payedit.cpp b/src/dialogs/payedit.cpp new file mode 100644 index 0000000..0ea679b --- /dev/null +++ b/src/dialogs/payedit.cpp @@ -0,0 +1,181 @@ +// +// C++ Implementation: shipping +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "misc.h" +#include "payedit.h" +#include "centbox.h" +#include "flagedit.h" + +#include "msinterface.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MPaymentEditor::MPaymentEditor(QWidget*par) + :QDialog(par) +{ + all=req->queryGetPaymentTypes().getpaytypes(); + setWindowTitle(tr("Edit Payment Options")); + setSizeGripEnabled(true); + + QHBoxLayout*hl; + QVBoxLayout*vl,*vl2; + setLayout(vl=new QVBoxLayout); + vl->addLayout(hl=new QHBoxLayout,1); + hl->addWidget(table=new QTableView,1); + table->setModel(model=new QStandardItemModel(this)); + table->setEditTriggers(QAbstractItemView::NoEditTriggers); + table->verticalHeader()->hide(); + updateTable(); + hl->addLayout(vl2=new QVBoxLayout,0); + QPushButton*p; + vl2->addWidget(p=new QPushButton(tr("Change Description"))); + connect(p,SIGNAL(clicked()),this,SLOT(changeDescription())); + vl2->addWidget(p=new QPushButton(tr("Change Data"))); + connect(p,SIGNAL(clicked()),this,SLOT(changeData())); + vl2->addWidget(p=new QPushButton(tr("Change Flags"))); + connect(p,SIGNAL(clicked()),this,SLOT(changeAvail())); + vl2->addSpacing(20); + vl2->addWidget(p=new QPushButton(tr("Add Option"))); + connect(p,SIGNAL(clicked()),this,SLOT(addNew())); + vl2->addWidget(p=new QPushButton(tr("Delete Option"))); + connect(p,SIGNAL(clicked()),this,SLOT(deletePay())); + vl2->addStretch(1); + + vl->addSpacing(15); + vl->addLayout(hl=new QHBoxLayout,0); + hl->addStretch(10); + hl->addWidget(p=new QPushButton(tr("Ok"))); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel"))); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); +} +void MPaymentEditor::updateTable() +{ + model->clear(); + model->insertColumns(0,5); + model->insertRows(0,all.size()); + model->setHorizontalHeaderLabels(QStringList()<setData(model->index(i,0),all[i].name().value()); + model->setData(model->index(i,1),all[i].description().value()); + model->setData(model->index(i,2),all[i].dataname().value()); + model->setData(model->index(i,3),all[i].datapreset().value()); + model->setData(model->index(i,4),all[i].flags().value()); + } + table->resizeColumnsToContents(); +} + +void MPaymentEditor::changeDescription() +{ + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + MOPaymentType s=all[idx.row()]; + //get new value + QString r=QInputDialog::getText(this,tr("Payment Option Description"),tr("Please select a new description for this payment option:"),QLineEdit::Normal,s.description()); + if(r=="")return; + s.setdescription(r); + MTSetPaymentType cs=MTSetPaymentType::query(s); + if(cs.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes: %1").arg(cs.errorString())); + return; + } + all[idx.row()]=cs.getpaytype(); + updateTable(); +} + +void MPaymentEditor::changeData() +{ + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + MOPaymentType s=all[idx.row()]; + //get new values + + //query server + MTSetPaymentType cs=MTSetPaymentType::query(s); + if(cs.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes: %1").arg(cs.errorString())); + return; + } + all[idx.row()]=cs.getpaytype(); + updateTable(); +} +void MPaymentEditor::changeAvail() +{ + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + MOPaymentType s=all[idx.row()]; + //get new value + s.setflags(MFlagEditor::edit(this,s.flags(),tr("Edit Flags of shipping option '%1'.").arg(s.description()))); + //save + MTSetPaymentType cs=MTSetPaymentType::query(s); + if(cs.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes.")); + return; + } + all[idx.row()]=s; + updateTable(); +} +void MPaymentEditor::addNew() +{ + //get data + //TODO: use a single dialog + QString dsc=QInputDialog::getText(this,tr("Shipping Option Description"),tr("Please select a new description for this new shipping option:")); + if(dsc=="")return; + //create the option + MOPaymentType s; + s.setdescription(dsc); + MTSetPaymentType cs=MTSetPaymentType::query(s); + if(cs.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Could not store the data: %1").arg(cs.errorString())); + return; + } + all.append(cs.getpaytype()); + updateTable(); +} + +void MPaymentEditor::deletePay() +{ + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //ask + MOPaymentType s=all[idx.row()]; + if(QMessageBox::question(this,tr("Really Delete?"),tr("Really delete payment option '%1'?").arg(s.description()),QMessageBox::Yes|QMessageBox::No)!=QMessageBox::Yes) + return; + //get shipping + MTDeletePaymentType ds=MTDeletePaymentType::query(s.name()); + if(ds.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to delete this option: %1").arg(ds.errorString())); + return; + } + all.removeAt(idx.row()); + updateTable(); +} diff --git a/src/dialogs/payedit.h b/src/dialogs/payedit.h new file mode 100644 index 0000000..a25da50 --- /dev/null +++ b/src/dialogs/payedit.h @@ -0,0 +1,44 @@ +// +// C++ Interface: shipping +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008-2011 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_PAYEDIT_H +#define MAGICSMOKE_PAYEDIT_H + +#include +#include + +class QStandardItemModel; +class QTableView; + +#include "MOPaymentType" + +class MPaymentEditor:public QDialog +{ + Q_OBJECT + public: + MPaymentEditor(QWidget*); + + private slots: + void changeDescription(); + void changeData(); + void changeAvail(); + void addNew(); + void deletePay(); + void updateTable(); + + private: + QListall; + QStandardItemModel*model; + QTableView*table; +}; + +#endif diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index fd8703e..be96f06 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -18,6 +18,7 @@ #include "templatedlg.h" #include "wizard.h" #include "backupdlg.h" +#include "payedit.h" #include "aclwin.h" #include "carttab.h" @@ -91,7 +92,8 @@ MOverview::MOverview(QString pk) m2->addSeparator(); m2->addAction(tr("&Deduct from voucher..."),this,SLOT(deductVoucher())); m2->addAction(tr("&Empty voucher..."),this,SLOT(emptyVoucher())); - m->addAction(tr("Edit &Shipping Options..."),this,SLOT(editShipping())); + m->addAction(tr("&Edit Shipping Options..."),this,SLOT(editShipping())); + m->addAction(tr("Edit &Payment Options..."),this,SLOT(editPayment())); m2=m->addMenu(tr("&Templates")); m2->addAction(tr("&Edit Templates..."),this,SLOT(editTemplates())); @@ -212,6 +214,12 @@ void MOverview::editShipping() carttab->updateShipping(); } +void MOverview::editPayment() +{ + MPaymentEditor se(this); + se.exec(); +} + void MOverview::tabChanged(int idx) { MTabWin::tabChanged(idx); diff --git a/src/mwin/overview.h b/src/mwin/overview.h index 01e80ef..cfa13d0 100644 --- a/src/mwin/overview.h +++ b/src/mwin/overview.h @@ -83,6 +83,8 @@ class MOverview:public MTabWin /**edit shipping options*/ void editShipping(); + ///edit payment options + void editPayment(); /**return a ticket or voucher*/ void ticketReturn(); diff --git a/wob/classes/order.wolf b/wob/classes/order.wolf index a1642f3..f4b36a6 100644 --- a/wob/classes/order.wolf +++ b/wob/classes/order.wolf @@ -308,4 +308,21 @@ + + + This class represents a kind of payment information + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wob/db/order.wolf b/wob/db/order.wolf index 6246a11..738a908 100644 --- a/wob/db/order.wolf +++ b/wob/db/order.wolf @@ -19,9 +19,11 @@ + filter: who can log payments with this method + This table contains all orders and sales. diff --git a/wob/transact/order.wolf b/wob/transact/order.wolf index 4de0d10..921e8e6 100644 --- a/wob/transact/order.wolf +++ b/wob/transact/order.wolf @@ -211,6 +211,8 @@ The order to be paidamount offered, it must be positive + the type of payment + additional data, like card number or date of bank transaction @@ -443,4 +445,30 @@ + + + returns the valid payment types + + + + + + + creates/changes a payment type + + + + + + + + + + deletes a payment type + + + + + + \ No newline at end of file diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 2898316..f1b36e1 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -336,6 +336,8 @@ class WOOrder extends WOOrderAbstract } //make corrections $ord->amountpaid+=$pay; + $ord->paytype=$trans->getpaytype(); + $ord->paydata=$trans->getpaydata(); $ord->update(); //return (redo object conversion: calculated data has changed!) $trans->setorder(WOOrder::fromTableorder($ord)); @@ -840,6 +842,25 @@ class WOOrder extends WOOrderAbstract //fetch and deliver result $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($oid)/*$ord*/)); } + + static public function setPayTypeTransaction($trans) + { + $pt=$trans->getpaytype(); + if(!is_a($pt,"WOPaymentType")){ + $trans->abortWithError(tr("Invalid Data")); + return; + } + //find it + $ptt=WTpaymenttype::getFromDB($pt->getname()); + if(!is_a($ptt,"WTpaymenttype")){ + $ptt=WTpaymenttype::newRow(); + } + //set data + $pt->toTablepaymenttype($ptt); + $ptt->insertOrUpdate(); + //done + $trans->setpaytype(WOPaymentType::fromTablepaymenttype($ptt)); + } }; ?> \ No newline at end of file