start for payment type support, so far very rudimentary
authorKonrad Rosenbaum <konrad@silmor.de>
Thu, 29 Dec 2011 14:44:30 +0000 (15:44 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Thu, 29 Dec 2011 14:44:30 +0000 (15:44 +0100)
src/dialogs/dialogs.pri
src/dialogs/orderwin.cpp
src/dialogs/payedit.cpp [new file with mode: 0644]
src/dialogs/payedit.h [new file with mode: 0644]
src/mwin/overview.cpp
src/mwin/overview.h
wob/classes/order.wolf
wob/db/order.wolf
wob/transact/order.wolf
www/inc/wext/order.php

index 2f57877..52975ea 100644 (file)
@@ -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
 
index d9cd83e..fe45e70 100644 (file)
@@ -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 (file)
index 0000000..0ea679b
--- /dev/null
@@ -0,0 +1,181 @@
+//
+// 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();
+}
diff --git a/src/dialogs/payedit.h b/src/dialogs/payedit.h
new file mode 100644 (file)
index 0000000..a25da50
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// C++ Interface: shipping
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008-2011
+//
+// Copyright: See README/COPYING.GPL files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_PAYEDIT_H
+#define MAGICSMOKE_PAYEDIT_H
+
+#include <QString>
+#include <QDialog>
+
+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:
+               QList<MOPaymentType>all;
+               QStandardItemModel*model;
+               QTableView*table;
+};
+
+#endif
index fd8703e..be96f06 100644 (file)
@@ -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);
index 01e80ef..cfa13d0 100644 (file)
@@ -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();
index a1642f3..f4b36a6 100644 (file)
                        <Map column="paydata"/>
                </Mapping>
        </Class>
+       
+       <Class name="PaymentType">
+               <Doc>This class represents a kind of payment information</Doc>
+               <Property name="name" type="astring"/>
+               <Property name="description" type="string"/>
+               <Property name="dataname" type="string"/>
+               <Property name="datapreset" type="string"/>
+               <Property name="flags" type="string"/>
+               <Mapping table="paymenttype">
+                       <Map column="paytype" property="name"/>
+                       <Map column="dataname"/>
+                       <Map column="description"/>
+                       <Map column="dataname"/>
+                       <Map column="datapreset"/>
+                       <Map column="flags"/>
+               </Mapping>
+       </Class>
 </Wolf>
\ No newline at end of file
index 6246a11..738a908 100644 (file)
                <Column name="paytype" type="string:64" primarykey="yes"/>
                <Column name="description" type="string"/>
                <Column name="dataname" type="string:64" null="yes"/>
+               <Column name="datapreset" type="string" null="yes"/>
                <Column name="flags" type="string">filter: who can log payments with this method</Column>
                
                <Preset><V col="paytype" val="cash"/><V col="description" val="default paytype: cash"/></Preset>
+               <Preset><V col="paytype" val="credit card"/><V col="description" val="credit card payment"/><V col="dataname" val="card data"/><V col="datapreset" val="date: %Y-%M-%D, card: ..."/></Preset>
        </Table>
        <Table name="order" backup="yes" audit="yes">
                <Doc>This table contains all orders and sales.</Doc>
index 4de0d10..921e8e6 100644 (file)
                <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
index 2898316..f1b36e1 100644 (file)
@@ -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