--- /dev/null
+//
+// C++ Implementation: shipping
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (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 <QApplication>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QHeaderView>
+#include <QStandardItemModel>
+#include <QTableView>
+#include <QPushButton>
+#include <QMessageBox>
+#include <QInputDialog>
+#include <QBoxLayout>
+
+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()<<tr("ID")<<tr("Description")<<tr("Data Name")<<tr("Data Default")<<tr("Flags"));
+ for(int i=0;i<all.size();i++){
+ model->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();
+}
<Input>
<Var name="orderid" type="int">The order to be paid</Var>
<Var name="amount" type="int">amount offered, it must be positive</Var>
+ <Var name="paytype" type="string">the type of payment</Var>
+ <Var name="paydata" type="string">additional data, like card number or date of bank transaction</Var>
</Input>
<Call lang="php" method="WOOrder::payForOrder($this);"/>
<Output>
<Var name="events" type="List:Event"/>
</Output>
</Transaction>
+
+ <Transaction name="GetPaymentTypes" update="no">
+ <Doc>returns the valid payment types</Doc>
+ <Call lang="php" method="$this->setpaytypes(WOPaymentType::fromTableArraypaymenttype(WTpaymenttype::selectFromDB()));"/>
+ <Output>
+ <Var name="paytypes" type="List:PaymentType"/>
+ </Output>
+ </Transaction>
+ <Transaction name="SetPaymentType">
+ <Doc>creates/changes a payment type</Doc>
+ <Input>
+ <Var name="paytype" type="PaymentType"/>
+ </Input>
+ <Call lang="php" method="WOOrder::setPayTypeTransaction($this);"/>
+ <Output>
+ <Var name="paytype" type="PaymentType"/>
+ </Output>
+ </Transaction>
+ <Transaction name="DeletePaymentType">
+ <Doc>deletes a payment type</Doc>
+ <Input>
+ <Var name="paytype" type="string"/>
+ </Input>
+ <Call lang="php" method="WOOrder::deletePayTypeTransaction($this);"/>
+ <Output/>
+ </Transaction>
</Wolf>
\ No newline at end of file