//
-// C++ Implementation: shipping
+// C++ Implementation: payment types
//
// Description:
//
//
-// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008-2011
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2011-2012
//
// Copyright: See README/COPYING.GPL files that come with this distribution
//
#include <QApplication>
#include <QDomDocument>
#include <QDomElement>
+#include <QFormLayout>
#include <QHeaderView>
+#include <QLabel>
#include <QStandardItemModel>
#include <QTableView>
#include <QPushButton>
QModelIndexList lst=table->selectionModel()->selectedIndexes();
if(lst.size()<1)return;
QModelIndex idx=lst[0];
- //get shipping
+ //get paytype
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());
QModelIndexList lst=table->selectionModel()->selectedIndexes();
if(lst.size()<1)return;
QModelIndex idx=lst[0];
- //get shipping
+ //get paytype
MOPaymentType s=all[idx.row()];
//get new values
-
+ QDialog d(this);
+ d.setWindowTitle(tr("Change Payment Data"));
+ QVBoxLayout*vl;
+ d.setLayout(vl=new QVBoxLayout);
+ QFormLayout*fl;
+ vl->addLayout(fl=new QFormLayout);
+ QLineEdit*dname,*dpat;
+ fl->addRow(tr("Data Name (human readable):"),dname=new QLineEdit);
+ dname->setText(s.dataname());
+ fl->addRow(tr("Data Default (pattern):"),dpat=new QLineEdit);
+ dpat->setText(s.datapreset());
+ vl->addWidget(new QLabel(tr("Hint: %Y=year, %M=month, %D=day, %%=%-sign, %O=order ID, %U=user")));
+ vl->addStretch(1);
+ QHBoxLayout*hl;
+ vl->addLayout(hl=new QHBoxLayout);
+ hl->addStretch(1);
+ QPushButton*p;
+ hl->addWidget(p=new QPushButton(tr("Ok")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+ //wait for user
+ if(d.exec()!=QDialog::Accepted)return;
+ s.setdataname(dname->text());
+ s.setdatapreset(dpat->text());
//query server
MTSetPaymentType cs=MTSetPaymentType::query(s);
if(cs.hasError()){
QModelIndexList lst=table->selectionModel()->selectedIndexes();
if(lst.size()<1)return;
QModelIndex idx=lst[0];
- //get shipping
+ //get paytype
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())));
+ s.setflags(MFlagEditor::edit(this,s.flags(),tr("Edit Flags of payment option '%1'.").arg(s.description())));
//save
MTSetPaymentType cs=MTSetPaymentType::query(s);
if(cs.hasError()){
}
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
+ //get new values
+ QDialog d(this);
+ d.setWindowTitle(tr("Create new Payment Option"));
+ QVBoxLayout*vl;
+ d.setLayout(vl=new QVBoxLayout);
+ QFormLayout*fl;
+ vl->addLayout(fl=new QFormLayout);
+ QLineEdit*dname,*dpat,*name,*descr;
+ fl->addRow(tr("Payment Type Name:"),name=new QLineEdit);
+ name->setValidator(new QRegExpValidator(QRegExp(tr("[a-zA-Z-/_\\(\\),\\.]{1,63}","payment type pattern - allow national chars!")),&d));
+ fl->addRow(tr("Description:"),descr=new QLineEdit);
+ fl->addRow(tr("Data Name (human readable):"),dname=new QLineEdit);
+ fl->addRow(tr("Data Default (pattern):"),dpat=new QLineEdit);
+ fl->addRow(new QLabel(tr("Hint: %Y=year, %M=month, %D=day, %%=%-sign, %O=order ID, %U=user")));
+ MFlagWidget*flgw;
+ fl->addRow(tr("Flags:"),flgw=new MFlagWidget);
+ flgw->setEditorLabel(tr("Edit flags of the new payment option:"));
+ vl->addStretch(1);
+ QHBoxLayout*hl;
+ vl->addLayout(hl=new QHBoxLayout);
+ hl->addStretch(1);
+ QPushButton*p;
+ hl->addWidget(p=new QPushButton(tr("Ok")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+ //wait for user
+ if(d.exec()!=QDialog::Accepted)return;
MOPaymentType s;
- s.setdescription(dsc);
+ s.setname(name->text());
+ s.setdescription(descr->text());
+ s.setdataname(dname->text());
+ s.setdatapreset(dpat->text());
+ s.setflags(flgw->flags());
+ //query server
MTSetPaymentType cs=MTSetPaymentType::query(s);
if(cs.hasError()){
- QMessageBox::warning(this,tr("Warning"),tr("Could not store the data: %1").arg(cs.errorString()));
+ QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes: %1").arg(cs.errorString()));
return;
}
all.append(cs.getpaytype());
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
+ //get payment type
MTDeletePaymentType ds=MTDeletePaymentType::query(s.name());
if(ds.hasError()){
QMessageBox::warning(this,tr("Warning"),tr("Unable to delete this option: %1").arg(ds.errorString()));
m->addAction(tr("&Close Session"),this,SLOT(close()));
//menus not connected to any specific tab...
m=addMenu(tr("&Actions"));
- m->addAction(tr("&Show all customers"),this,SLOT(customerMgmt()));
+ m->addAction(tr("&Show all customers"),this,SLOT(customerMgmt()))
+ ->setEnabled(req->hasRight(req->RGetAllCustomerNames));
QMenu*m2=m->addMenu(tr("Tickets and &Vouchers"));
m2->addAction(tr("Return &ticket or voucher..."),this,SLOT(ticketReturn()))
- ->setEnabled(req->RReturnTicketVoucher);
+ ->setEnabled(req->hasRight(req->RReturnTicketVoucher));
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 &Payment Options..."),this,SLOT(editPayment()));
+ m2->addAction(tr("&Deduct from voucher..."),this,SLOT(deductVoucher()))
+ ->setEnabled(req->hasRight(req->RDeductVoucher));
+ m2->addAction(tr("&Empty voucher..."),this,SLOT(emptyVoucher()))
+ ->setEnabled(req->hasRight(req->REmptyVoucher));
+ m->addAction(tr("&Edit Shipping Options..."),this,SLOT(editShipping()))
+ ->setEnabled(req->hasRight(req->RGetAllShipping));
+ m->addAction(tr("Edit &Payment Options..."),this,SLOT(editPayment()))
+ ->setEnabled(req->hasRight(req->RGetPaymentTypes));
m2=m->addMenu(tr("&Templates"));
- m2->addAction(tr("&Edit Templates..."),this,SLOT(editTemplates()));
- m2->addAction(tr("&Update Templates Now"),req,SLOT(updateTemplates()));
+ m2->addAction(tr("&Edit Templates..."),this,SLOT(editTemplates()))
+ ->setEnabled(req->hasRight(req->RSetTemplate));
+ m2->addAction(tr("&Update Templates Now"),req,SLOT(updateTemplates()))
+ ->setEnabled(req->hasRight(req->RGetTemplateList));
m2=m->addMenu(tr("&Configuration"));
m2->addAction(tr("&Auto-Refresh settings..."),this,SLOT(setRefresh()));