#include <TimeStamp>
#include <QBoxLayout>
+#include <QCheckBox>
#include <QComboBox>
#include <QDateTimeEdit>
+#include <QDebug>
+#include <QFormLayout>
#include <QInputDialog>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QSettings>
+#include <QSpinBox>
#include <QStandardItemModel>
#include <QTableView>
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));
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;
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"<<d.mySelfOnly()<<"user"<<d.userName()<<"incall"<<d.includeAll()<<"old"<<d.oldest();
+ QList<MOOrderInfo>orders;
+ QList<MOCustomerInfo>cust;
+ 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;i<orders.size();i++){
+ addOrderToModel(orders[i],cust);
+ }
+ ordermode->setCurrentIndex(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()){
+ QList<MOUser>ul=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);
+}
<Preset><V col="rolename" val="OrderAdvanced"/><V col="rightname" val="ResetCustomerPassword"/></Preset>
<Preset><V col="rolename" val="OrderAdvanced"/><V col="rightname" val="ReturnTicketVoucher"/></Preset>
<Preset><V col="rolename" val="OrderAdvanced"/><V col="rightname" val="ChangeOrderAddress"/></Preset>
+ <Preset><V col="rolename" val="OrderAdvanced"/><V col="rightname" val="GetMyOrders"/></Preset>
<Preset><V col="rolename" val="OrderCancelling"/><V col="rightname" val="CancelOrder"/></Preset>
<Preset><V col="rolename" val="OrderCancelling"/><V col="rightname" val="OrderChangeShipping"/></Preset>
<Preset><V col="rolename" val="OrderCancelling"/><V col="rightname" val="ReturnTicketVoucher"/></Preset>
<Preset><V col="rolename" val="OrderHighPrivilege"/><V col="rightname" val="UseTicket"/></Preset>
<Preset><V col="rolename" val="OrderHighPrivilege"/><V col="rightname" val="UseVoucher"/></Preset>
<Preset><V col="rolename" val="OrderHighPrivilege"/><V col="rightname" val="ChangeOrderAddress"/></Preset>
+ <Preset><V col="rolename" val="OrderHighPrivilege"/><V col="rightname" val="GetMyOrders"/></Preset>
+ <Preset><V col="rolename" val="OrderHighPrivilege"/><V col="rightname" val="GetOrdersByUser"/></Preset>
<Preset><V col="rolename" val="OrderListing"/><V col="rightname" val="GetOrder"/></Preset>
<Preset><V col="rolename" val="OrderListing"/><V col="rightname" val="GetOrderByBarcode"/></Preset>
<Preset><V col="rolename" val="OrderListing"/><V col="rightname" val="GetOrderList"/></Preset>
</Output>
</Transaction>
+ <Transaction name="GetMyOrders" updating="no">
+ <Doc>returns all orders created by the current user</Doc>
+ <Input>
+ <Var name="oldest" type="int64">unix timestamp for the oldest order to be returned (compared with ordertime)</Var>
+ <Var name="includeall" type="bool">if true: include all orders that the user ever touched</Var>
+ </Input>
+ <Call lang="php" method="WOOrderInfo::getOrdersByUser($this,true);"/>
+ <Output>
+ <Var name="orders" type="List:OrderInfo"/>
+ <Var name="customers" type="List:CustomerInfo"/>
+ </Output>
+ </Transaction>
+ <Transaction name="GetOrdersByUser" updating="no">
+ <Doc>returns all orders created by the a specified user</Doc>
+ <Input>
+ <Var name="oldest" type="int64">unix timestamp for the oldest order to be returned (compared with ordertime)</Var>
+ <Var name="includeall" type="bool">if true: include all orders that the user ever touched</Var>
+ <Var name="username" type="astring">the name of the user to look for</Var>
+ </Input>
+ <Call lang="php" method="WOOrderInfo::getOrdersByUser($this,false);"/>
+ <Output>
+ <Var name="orders" type="List:OrderInfo"/>
+ <Var name="customers" type="List:CustomerInfo"/>
+ </Output>
+ </Transaction>
+
<Transaction name="GetOrderByBarcode" updating="no">
<Doc>retrieves the order in which a specific ticket or voucher was bought</Doc>
<Input>
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)