From 99aa2d0ed236dd849b02f53bdaee16fa1c270c6c Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Thu, 29 Dec 2011 13:36:13 +0100 Subject: [PATCH] implement order search by user --- src/mwin/orderstab.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++++ src/mwin/orderstab.h | 22 +++++++++- wob/db/user.wolf | 3 + wob/transact/order.wolf | 26 +++++++++++ www/inc/wext/order.php | 41 +++++++++++++++++ 5 files changed, 202 insertions(+), 1 deletions(-) diff --git a/src/mwin/orderstab.cpp b/src/mwin/orderstab.cpp index 7f421db..f5146a6 100644 --- a/src/mwin/orderstab.cpp +++ b/src/mwin/orderstab.cpp @@ -23,13 +23,17 @@ #include #include +#include #include #include +#include +#include #include #include #include #include #include +#include #include #include @@ -87,6 +91,9 @@ MOrdersTab::MOrdersTab(QString pk) vl->addWidget(p=new QPushButton(tr("Find by Customer...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderByCustomer())); p->setEnabled(req->hasRight(req->RGetOrdersByCustomer)); + vl->addWidget(p=new QPushButton(tr("Find by User...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(orderByUser())); + p->setEnabled(req->hasRight(req->RGetOrdersByUser) || req->hasRight(req->RGetMyOrders)); vl->addWidget(p=new QPushButton(tr("Find by Order ID...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderByOrder())); p->setEnabled(req->hasRight(req->RGetOrder)); @@ -110,6 +117,7 @@ qint64 MOrdersTab::oldestOrderStamp(OrderTimeStampMode mode,int age) case OldestForAll:age=set.value("maxorderage",0).toInt();break; case OldestForOpen:age=set.value("maxorderageopen",0).toInt();break; case OldestForEvent:age=set.value("maxorderageevent",0).toInt();break; + case OldestForUser://currently we re-use the customer setting case OldestForCustomer:age=set.value("maxorderagecust",0).toInt();break; case OldestForSince:age=set.value("deforderagesince",7).toInt();break; default: age=0;break; @@ -370,3 +378,106 @@ void MOrdersTab::orderByOrder() om->setAttribute(Qt::WA_DeleteOnClose); om->show(); } + +void MOrdersTab::orderByUser() +{ + MOrdersByUserDlg d(oldestOrderStamp(OldestForUser),this); + if(d.exec()!=QDialog::Accepted)return; + resetModel(); +// qDebug()<<"searching: my"<orders; + QListcust; + if(d.mySelfOnly()){ + MTGetMyOrders gmo=req->queryGetMyOrders(d.oldest(),d.includeAll()); + if(gmo.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to get user orders, server error: %1").arg(gmo.errorString())); + return; + } + orders=gmo.getorders(); + cust=gmo.getcustomers(); + }else{ + MTGetOrdersByUser obu=req->queryGetOrdersByUser(d.oldest(),d.includeAll(),d.userName()); + if(obu.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to get user orders, server error: %1").arg(obu.errorString())); + return; + } + orders=obu.getorders(); + cust=obu.getcustomers(); + } + for(int i=0;isetCurrentIndex(ordermode->count()-1); +} + +MOrdersByUserDlg::MOrdersByUserDlg(int olddef,QWidget* parent, Qt::WindowFlags f): QDialog(parent, f) +{ + setWindowTitle(tr("Select User Criteria")); + //layout + QVBoxLayout*vl; + setLayout(vl=new QVBoxLayout); + QFormLayout*fl; + vl->addLayout(fl=new QFormLayout); + vl->addStretch(1); + //buttons + QHBoxLayout*hl; + vl->addLayout(hl=new QHBoxLayout); + hl->addStretch(1); + QPushButton*p; + 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())); + //form + fl->addRow(tr("My orders:"),m_myself=new QCheckBox(tr("look for my own orders"))); + fl->addRow(tr("User Name:"),m_uname=new QComboBox); + m_uname->setEditable(true); + connect(m_myself,SIGNAL(toggled(bool)),m_uname,SLOT(setDisabled(bool))); + fl->addRow(tr("Maximum Age (days):"),m_days=new QSpinBox); + m_days->setRange(0,9999); + m_days->setValue(olddef); + fl->addRow(tr("Limit:"),m_incall=new QCheckBox(tr("Include all orders the user touched"))); + //init and preselect + if(req->hasRight(req->RGetOrdersByUser)){ + //try to get all user names + if(req->hasRight(req->RGetAllUsers)){ + MTGetAllUsers gau=req->queryGetAllUsers(); + if(!gau.hasError()){ + QListul=gau.getusers(); + foreach(MOUser u,ul){ + m_uname->addItem(u.name()); + } + } + } + //this would be odd, but it is possible + if(!req->hasRight(req->RGetMyOrders)) + m_myself->setEnabled(false); + }else{ + m_myself->setChecked(true); + m_myself->setEnabled(false); + } + //use own name as preselection + m_uname->setEditText(req->currentUser()); +} + +bool MOrdersByUserDlg::includeAll() const +{ + return m_incall->isChecked(); +} + +bool MOrdersByUserDlg::mySelfOnly() const +{ + return m_myself->isChecked(); +} + +QString MOrdersByUserDlg::userName() const +{ + return m_uname->currentText(); +} + +qint64 MOrdersByUserDlg::oldest() const +{ + qint64 d=m_days->value(); + if(d<=0)return 0; + return QDateTime::currentDateTime().toTime_t() - (d*86400); +} diff --git a/src/mwin/orderstab.h b/src/mwin/orderstab.h index fb13381..9942ccd 100644 --- a/src/mwin/orderstab.h +++ b/src/mwin/orderstab.h @@ -13,7 +13,7 @@ #ifndef MAGICSMOKE_ORDERSTAB_H #define MAGICSMOKE_ORDERSTAB_H -#include +#include class QAction; class QCheckBox; @@ -54,6 +54,8 @@ class MOrdersTab:public QWidget void orderByOrder(); /**display all orders since a specific date*/ void orderSinceDate(); + ///find and display orders by user who created it + void orderByUser(); signals: /**needs to be connected to the event tab*/ @@ -71,6 +73,7 @@ class MOrdersTab:public QWidget OldestForEvent, OldestForCustomer, OldestForSince, + OldestForUser, }; /**returns timestamp for oldest order; if age is given it returns a timestamp age days in the past, if age is not given it uses the configured time*/ qint64 oldestOrderStamp(OrderTimeStampMode mode,int age=-1); @@ -83,4 +86,21 @@ class MOrdersTab:public QWidget QComboBox*ordermode; }; +class MOrdersByUserDlg:public QDialog +{ + Q_OBJECT + public: + MOrdersByUserDlg(int oldestdefault, QWidget* parent, Qt::WindowFlags f = 0); + + bool mySelfOnly()const; + QString userName()const; + bool includeAll()const; + qint64 oldest()const; + + private: + QComboBox*m_uname; + QCheckBox*m_myself,*m_incall; + QSpinBox*m_days; +}; + #endif diff --git a/wob/db/user.wolf b/wob/db/user.wolf index 0768b14..be6e851 100644 --- a/wob/db/user.wolf +++ b/wob/db/user.wolf @@ -124,6 +124,7 @@ + @@ -192,6 +193,8 @@ + + diff --git a/wob/transact/order.wolf b/wob/transact/order.wolf index 8b37434..0e401fb 100644 --- a/wob/transact/order.wolf +++ b/wob/transact/order.wolf @@ -101,6 +101,32 @@ + + returns all orders created by the current user + + unix timestamp for the oldest order to be returned (compared with ordertime) + if true: include all orders that the user ever touched + + + + + + + + + returns all orders created by the a specified user + + unix timestamp for the oldest order to be returned (compared with ordertime) + if true: include all orders that the user ever touched + the name of the user to look for + + + + + + + + retrieves the order in which a specific ticket or voucher was bought diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 6594835..2898316 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -94,6 +94,47 @@ class WOOrderInfo extends WOOrderInfoAbstract global $db; $trans->setorders(self::fromTableArrayorder(WTorder::selectFromDB("customerid=".$db->escapeInt($cid)." AND ordertime>=".$db->escapeInt($old),"ORDER BY orderid"))); } + + /**called from GetOrdersByUser and getMyOrders transaction*/ + static public function getOrdersByUser($trans,$meonly) + { + global $session; + if($meonly) + $uid=$session->currentUserName(); + else + $uid=$trans->getusername(); + $old=$trans->getoldest(); + if($old===false)$old=0; + $incall=$trans->getincludeall(); + //get primary list: orders of this user + global $db; + $prim=WTorder::selectFromDB("soldby=".$db->escapeString($uid)." AND ordertime>=".$db->escapeInt($old)); + //get secondary list: orders the user touched + if($incall){ + $seca=WTorder_audit::selectFromDB("audituname=".$db->escapeString($uid)." AND audittime>=".$db->escapeInt($old)); + $rs=array(); + foreach($seca as $oa) + if(!in_array($oa->orderid,$rs)) + $rs[]=$oa->orderid; + $sec=WTorder::selectFromDB("orderid IN ".$db->escapeIntList($rs)); + }else $sec=array(); + //merge and sort + $res=array(); + $cst=array(); + foreach($prim as $o){ + $res[$o->orderid]=$o; + $cst[]=$o->customerid; + } + foreach($sec as $o){ + $res[$o->orderid]=$o; + $cst[]=$o->customerid; + } + ksort($res); + //construct result + $trans->setorders(self::fromTableArrayorder(array_values($res))); + $cust=WTcustomer::selectFromDB("customerid IN ".$db->escapeIntList(array_unique($cst,SORT_NUMERIC))); + $trans->setcustomers(WOCustomerInfo::fromTableArraycustomer($cust)); + } /**helper function for several transactions: selects customers by their IDs references by the given order info objects*/ static protected function getCustomerListByOrders(array $olist) -- 1.7.2.5