added ordersbyevent function
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 31 Aug 2008 11:23:39 +0000 (11:23 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 31 Aug 2008 11:23:39 +0000 (11:23 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@170 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/eventedit.cpp
src/eventedit.h
src/overview.cpp
src/overview.h
src/webrequest.cpp
src/webrequest.h

index 47c0783..0590ba6 100644 (file)
@@ -50,7 +50,12 @@ MEventEditor::MEventEditor(QWidget*w,MWebRequest*r,qint32 id)
        setLayout(vl=new QVBoxLayout);
        vl->addLayout(gl=new QGridLayout);
        
-       gl->addWidget(lab=new QLabel(tr("Title:")),lctr,0);
+       gl->addWidget(lab=new QLabel(tr("ID:")),lctr,0);
+       lab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+       gl->addWidget(eventid=new QLabel,lctr,1);
+       eventid->setText(QString::number(event.eventId()));
+       
+       gl->addWidget(lab=new QLabel(tr("Title:")),++lctr,0);
        lab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
        gl->addWidget(title=new QLineEdit,lctr,1);
        title->setText(event.title());
index e105f39..63a6a1b 100644 (file)
@@ -23,6 +23,7 @@ class QLineEdit;
 class QTextEdit;
 class QCheckBox;
 class QSpinBox;
+class QLabel;
 
 class MEventEditor:public QDialog
 {
@@ -41,6 +42,7 @@ class MEventEditor:public QDialog
                QTextEdit*description;
                QCheckBox*cancelcheck;
                QSpinBox*capacity;
+               QLabel*eventid;
 };
 
 
index e65d9c2..2375204 100644 (file)
@@ -80,6 +80,12 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        m=mb->addMenu(tr("&Misc"));
        m->addAction(tr("&Return ticket..."),this,SLOT(ticketReturn()));
        
+       m=mb->addMenu(tr("&Admin"));
+       m->setEnabled(req->hasRole("_admin"));
+       m->addAction(tr("&Schedule Backup..."));
+       m->addAction(tr("&Backup now..."));
+       m->addAction(tr("&Restore..."));
+       
        //tabs
        setCentralWidget(tab=new QTabWidget);
        connect(tab,SIGNAL(currentChanged(int)),this,SLOT(tabChanged()));
@@ -189,6 +195,9 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        vl->addWidget(p=new QPushButton(tr("Find by Ticket...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(orderByTicket()));
        p->setEnabled(req->hasRole("orderbyticket"));
+       vl->addWidget(p=new QPushButton(tr("Find by Event...")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(orderByEvent()));
+       p->setEnabled(req->hasRole("getordersbyevents"));
        vl->addStretch(10);
        
        //Entrance Control Tab
@@ -981,6 +990,63 @@ void MOverview::orderByTicket()
        om->show();
 }
 
+void MOverview::orderByEvent()
+{
+       //display selection dialog
+       QDialog d(this);
+       d.setWindowTitle(tr("Select Event"));
+       QVBoxLayout*vl;
+       QHBoxLayout*hl;
+       d.setLayout(vl=new QVBoxLayout);
+       QTableView*tv;
+       vl->addWidget(tv=new QTableView,10);
+       tv->setEditTriggers(QAbstractItemView::NoEditTriggers);
+       tv->setModel(eventmodel);
+       tv->resizeColumnsToContents();
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addStretch(10);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("Ok")),0);
+       connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+       hl->addWidget(p=new QPushButton(tr("Cancel")),0);
+       connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+       //wait for user
+       if(d.exec()!=QDialog::Accepted)
+               return;
+       //get selection
+       QModelIndexList ilst=tv->selectionModel()->selectedIndexes();
+       if(ilst.size()<1){
+               qDebug("nothing selected");
+               return;
+       }
+       //get events
+       QList<int>eventids;
+       for(int i=0;i<ilst.size();i++){
+               int eid=eventmodel->data(eventmodel->index(ilst[i].row(),0),Qt::UserRole).toInt();
+               if(!eventids.contains(eid))eventids.append(eid);
+       }
+       //request data and display
+       //TODO: unify this part with updateOrders
+       ordermodel->clear();
+       ordermodel->setHorizontalHeaderLabels(QStringList()<<tr("Status")<<tr("Total")<<tr("Paid")<<tr("Customer"));
+       QList<MOrder> orders=req->getOrdersByEvents(eventids);
+       if(orders.size()==0)return;
+       QList<MCustomer> cust=req->getAllCustomers();
+       for(int cl=0;cl<orders.size();cl++){
+               ordermodel->insertRow(cl);
+               ordermodel->setHeaderData(cl,Qt::Vertical,orders[cl].orderID());
+               ordermodel->setData(ordermodel->index(cl,0),orders[cl].orderStatusString());
+               ordermodel->setData(ordermodel->index(cl,0),orders[cl].orderID(),Qt::UserRole);
+               ordermodel->setData(ordermodel->index(cl,1),orders[cl].totalPriceString());
+               ordermodel->setData(ordermodel->index(cl,2),orders[cl].amountPaidString());
+               int cid=orders[cl].customerID();
+               //TODO: make this more effective:
+               for(int j=0;j<cust.size();j++)
+                       if(cust[j].customerID()==cid)
+                               ordermodel->setData(ordermodel->index(cl,3),cust[j].name());
+       }
+}
+
 void MOverview::uploadTemplate()
 {
        //get file
index 6e5fb98..cb6ee5e 100644 (file)
@@ -124,6 +124,8 @@ class MOverview:public QMainWindow
                void ticketReturn();
                /**find an order by ticket*/
                void orderByTicket();
+               /**find/select orders by event*/
+               void orderByEvent();
                
        private:
                //my session object
index 39f2422..c6a3bcf 100644 (file)
@@ -476,6 +476,33 @@ QList<MOrder> MWebRequest::getAllOrders()
        return ret;
 }
 
+QList<MOrder> MWebRequest::getOrdersByEvents(QList<int>evids)
+{
+       errstr="";
+       QString evs;
+       for(int i=0;i<evids.size();i++)
+               evs+=QString::number(evids[i])+" ";
+       if(!request("getordersbyevents",evs.trimmed().toUtf8()))return QList<MOrder>();
+       if(responseStatus()!=Ok)return QList<MOrder>();
+       //parse return document
+       QDomDocument doc;
+       QString msg;int ln,cl;
+       if(!doc.setContent(rspdata,&msg,&ln,&cl)){
+               errstr=tr("Error parsing OrderList XML data (line %1 column %2): %3").arg(ln).arg(cl).arg(msg);
+               return QList<MOrder>();
+       }
+       QDomElement root=doc.documentElement();
+       QDomNodeList nl=root.elementsByTagName("Order");
+       QList<MOrder>ret;
+       for(int i=0;i<nl.size();i++){
+               QDomElement el=nl.at(i).toElement();
+               if(el.isNull())continue;
+               MOrder mo(this,el);
+               if(mo.isValid())ret.append(mo);
+       }
+       return ret;
+}
+
 QByteArray MWebRequest::responseBody()
 {
        return rspdata;
index 546542d..c34e45b 100644 (file)
@@ -94,6 +94,9 @@ class MWebRequest:public QObject
                /**returns a list of all orders*/
                QList<MOrder>getAllOrders();
                
+               /**returns a list of all orders that order from one of the specified events*/
+               QList<MOrder>getOrdersByEvents(QList<int>);
+               
                /**return current host name of this session*/
                QString hostName();