make payment types editable
authorKonrad Rosenbaum <konrad@silmor.de>
Fri, 30 Dec 2011 13:11:38 +0000 (14:11 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Fri, 30 Dec 2011 13:11:38 +0000 (14:11 +0100)
src/dialogs/payedit.cpp
src/mwin/overview.cpp
www/inc/wext/order.php

index 0ea679b..2abf9d4 100644 (file)
@@ -1,10 +1,10 @@
 //
-// 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
 //
@@ -20,7 +20,9 @@
 #include <QApplication>
 #include <QDomDocument>
 #include <QDomElement>
+#include <QFormLayout>
 #include <QHeaderView>
+#include <QLabel>
 #include <QStandardItemModel>
 #include <QTableView>
 #include <QPushButton>
@@ -89,7 +91,7 @@ void MPaymentEditor::changeDescription()
        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());
@@ -110,10 +112,34 @@ void MPaymentEditor::changeData()
        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()){
@@ -129,10 +155,10 @@ void MPaymentEditor::changeAvail()
        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()){
@@ -144,16 +170,44 @@ void MPaymentEditor::changeAvail()
 }
 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());
@@ -170,7 +224,7 @@ void MPaymentEditor::deletePay()
        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()));
index be96f06..5781a49 100644 (file)
@@ -84,20 +84,27 @@ MOverview::MOverview(QString pk)
        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()));
index f1b36e1..266cdce 100644 (file)
@@ -861,6 +861,17 @@ class WOOrder extends WOOrderAbstract
                //done
                $trans->setpaytype(WOPaymentType::fromTablepaymenttype($ptt));
        }
+       
+       static public function deletePayTypeTransaction($trans)
+       {
+               //find it
+               $ptt=WTpaymenttype::getFromDB($trans->getpaytype());
+               if(!is_a($ptt,"WTpaymenttype")){
+                       $ptt=WTpaymenttype::newRow();
+               }
+               //delete
+               $ptt->deleteFromDb();
+       }
 };
 
 ?>
\ No newline at end of file