make orders selectable by customer#
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 6 Sep 2008 14:24:48 +0000 (14:24 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 6 Sep 2008 14:24:48 +0000 (14:24 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@174 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/overview.cpp
src/overview.h

index 2375204..cc47cb1 100644 (file)
@@ -178,6 +178,8 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        ordermode->addItem(tr("Outstanding Payments"),ORDERPAY);
        ordermode->addItem(tr("Outstanding Refunds"),ORDERREFUND);
        ordermode->addItem(tr("Undelivered Orders"),ORDERUNSENT);
+       //make sure this entry is the last one, since we use count()-1 to select it
+       ordermode->addItem(tr("-search result-"),ORDERNONE);
        connect(ordermode,SIGNAL(currentIndexChanged(int)),this,SLOT(updateOrders()));
        vl->addWidget(ordertable=new QTableView);
        ordertable->setModel(ordermodel=new QStandardItemModel(this));
@@ -198,6 +200,9 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        vl->addWidget(p=new QPushButton(tr("Find by Event...")),0);
        connect(p,SIGNAL(clicked()),this,SLOT(orderByEvent()));
        p->setEnabled(req->hasRole("getordersbyevents"));
+       vl->addWidget(p=new QPushButton(tr("Find by Customer...")),0);
+       connect(p,SIGNAL(clicked()),this,SLOT(orderByCustomer()));
+       p->setEnabled(req->hasRole("getorderlist"));
        vl->addStretch(10);
        
        //Entrance Control Tab
@@ -1045,6 +1050,46 @@ void MOverview::orderByEvent()
                        if(cust[j].customerID()==cid)
                                ordermodel->setData(ordermodel->index(cl,3),cust[j].name());
        }
+       ordermode->setCurrentIndex(ordermode->count()-1);
+}
+
+void MOverview::orderByCustomer()
+{
+       //display selection dialog
+       MCustomerListDialog mcl(req,this,true);
+       //wait for user
+       if(mcl.exec()!=QDialog::Accepted)
+               return;
+       //get selection
+       MCustomer cst=mcl.getCustomer();
+       if(!cst.isValid()){
+               qDebug("nothing selected");
+               return;
+       }
+       qint64 custid=cst.customerID();
+       //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->getAllOrders();
+       if(orders.size()==0)return;
+       QList<MCustomer> cust=req->getAllCustomers();
+       int cl=0;
+       for(int i=0;i<orders.size();i++){
+               //filter
+               if(orders[i].customerID()!=custid)continue;
+               //put into table
+               ordermodel->insertRow(cl);
+               ordermodel->setHeaderData(cl,Qt::Vertical,orders[i].orderID());
+               ordermodel->setData(ordermodel->index(cl,0),orders[i].orderStatusString());
+               ordermodel->setData(ordermodel->index(cl,0),orders[i].orderID(),Qt::UserRole);
+               ordermodel->setData(ordermodel->index(cl,1),orders[i].totalPriceString());
+               ordermodel->setData(ordermodel->index(cl,2),orders[i].amountPaidString());
+               ordermodel->setData(ordermodel->index(cl,3),cst.name());
+               //count up
+               cl++;
+       }
+       ordermode->setCurrentIndex(ordermode->count()-1);
 }
 
 void MOverview::uploadTemplate()
index cb6ee5e..2a747a6 100644 (file)
@@ -126,6 +126,8 @@ class MOverview:public QMainWindow
                void orderByTicket();
                /**find/select orders by event*/
                void orderByEvent();
+               /**find/select orders by customer*/
+               void orderByCustomer();
                
        private:
                //my session object