From: konrad Date: Tue, 29 Dec 2009 17:08:54 +0000 (+0000) Subject: *implement find order by customer X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=1ab8ba7d155ce3469c3feeaa4142126b0ba9fa98;p=konrad%2Fsmoke.git *implement find order by customer *correction: make sure mappings are translated in order git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@368 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/dialogs/customerdlg.cpp b/src/dialogs/customerdlg.cpp index c15affa..dc04e8f 100644 --- a/src/dialogs/customerdlg.cpp +++ b/src/dialogs/customerdlg.cpp @@ -94,19 +94,16 @@ void MCustomerListDialog::updateList(int nid) } //go to server MTGetAllCustomerNames gac=req->queryGetAllCustomerNames(); - if(gac.stage()!=gac.Success)return; + if(gac.hasError())return; m_list.clear(); - QListcl=gac.getcustomers(); - //FIXME -// for(int i=0;iclear(); m_listmodel->insertRows(0,m_list.size()); m_listmodel->insertColumn(0); for(int i=0;iindex(i,0); - m_listmodel->setData(idx,m_list[i].name().value()); + m_listmodel->setData(idx,m_list[i].fullName()); m_listmodel->setData(idx,i,Qt::UserRole); } m_listmodel->sort(0); @@ -116,21 +113,21 @@ void MCustomerListDialog::updateList(int nid) QModelIndex idx=m_proxymodel->index(i,0); int j=m_proxymodel->data(idx,Qt::UserRole).toInt(); if(j<0 || j>=m_list.size())continue; - if(nid==m_list[j].id()){ + if(nid==m_list[j].customerid()){ m_listview->setCurrentIndex(idx); break; } } } -MCustomer MCustomerListDialog::getCustomer() +MOCustomerInfo MCustomerListDialog::getCustomer() { //get selection QModelIndex idx=m_listview->currentIndex(); - if(!idx.isValid())return MCustomer(); + if(!idx.isValid())return MOCustomerInfo(); //return object int i=m_proxymodel->data(idx,Qt::UserRole).toInt(); - if(i<0||i>=m_list.size())return MCustomer(); + if(i<0||i>=m_list.size())return MOCustomerInfo(); return m_list[i]; } @@ -142,14 +139,16 @@ void MCustomerListDialog::newCustomer() } void MCustomerListDialog::editCustomer() { - //1get selection + //get selection QModelIndex idx=m_listview->currentIndex(); if(!idx.isValid())return; - //return object + //get object int i=m_proxymodel->data(idx,Qt::UserRole).toInt(); if(i<0||i>=m_list.size())return; + MTGetCustomer gc=req->queryGetCustomer(m_list[i].customerid()); + if(gc.hasError())return; //open dialog - MCustomerDialog cd(m_list[i],this); + MCustomerDialog cd(gc.getcustomer().value(),this); if(cd.exec()==QDialog::Accepted) updateList(); } @@ -186,26 +185,15 @@ void MCustomerListDialog::deleteCustomer() hl->addWidget(p=new QPushButton(tr("&No"))); connect(p,SIGNAL(clicked()),&d,SLOT(reject())); if(d.exec()!=QDialog::Accepted)return; - //compose request - QString rd=QString::number(m_list[dusr].id()); - if(cb->isChecked()){ - int musr=m_listmodel->data(m_listmodel->index(cm->currentIndex(),0),Qt::UserRole).toInt(); - rd+=" "; - rd+=QString::number(m_list[musr].id()); - } //delete it - /*TODO - if(!req->request("deletecustomer",rd.toAscii())){ - QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer.")); - return; - } - if(m_req->responseStatus()!=MWebRequest::Ok){ - QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer: %1").arg(qApp->translate("php::",m_req->responseBody()))); + int musr=m_listmodel->data(m_listmodel->index(cm->currentIndex(),0),Qt::UserRole).toInt(); + MTDeleteCustomer dc=req->queryDeleteCustomer(m_list[dusr].customerid(),cb->isChecked()?m_list[musr].customerid().value():-1); + if(dc.hasError()){ + QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer: %1").arg(dc.errorString())); return; } //update view updateList(); - */ } diff --git a/src/dialogs/customerdlg.h b/src/dialogs/customerdlg.h index cc242f2..abf04d6 100644 --- a/src/dialogs/customerdlg.h +++ b/src/dialogs/customerdlg.h @@ -17,7 +17,7 @@ #include #include -#include "customer.h" +#include "MOCustomerInfo.h" class QListView; class QStandardItemModel; @@ -33,7 +33,7 @@ class MCustomerListDialog:public QDialog MCustomerListDialog(QWidget*,bool isselect=false,qint64 selected=-1); /**returns the selected customer*/ - MCustomer getCustomer(); + MOCustomerInfo getCustomer(); private slots: /**internal: new customer*/ @@ -44,7 +44,7 @@ class MCustomerListDialog:public QDialog void deleteCustomer(); private: - QList m_list; + QList m_list; QListView*m_listview; QStandardItemModel*m_listmodel; QSortFilterProxyModel*m_proxymodel; @@ -58,6 +58,7 @@ class QLineEdit; class QTextEdit; class QLabel; +#include"customer.h" /**edit a specific customer*/ class MCustomerDialog:public QDialog { diff --git a/src/iface/customer.h b/src/iface/customer.h index 55c7589..7048fe8 100644 --- a/src/iface/customer.h +++ b/src/iface/customer.h @@ -15,7 +15,7 @@ #include -#include "MOCustomerShort.h" +// #include "MOCustomerShort.h" #include "MOCustomer.h" /**this class expands on MOCustomer to add some convenience methods*/ diff --git a/src/mwin/orderstab.cpp b/src/mwin/orderstab.cpp index d5f4dd3..009b688 100644 --- a/src/mwin/orderstab.cpp +++ b/src/mwin/orderstab.cpp @@ -16,6 +16,8 @@ #include "msinterface.h" #include "orderwin.h" +#include "customerdlg.h" + #include "orderstab.h" #include @@ -79,7 +81,7 @@ MOrdersTab::MOrdersTab(QString pk) p->setEnabled(req->hasRight(req->RGetOrdersByEvents)); vl->addWidget(p=new QPushButton(tr("Find by Customer...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderByCustomer())); - p->setEnabled(req->hasRole("getorderlist")); + p->setEnabled(req->hasRight(req->RGetOrdersByCustomer)); vl->addWidget(p=new QPushButton(tr("Find by Order ID...")),0); connect(p,SIGNAL(clicked()),this,SLOT(orderByOrder())); p->setEnabled(req->hasRole("getorder")); @@ -143,9 +145,9 @@ void MOrdersTab::addOrderToModel(const MOOrderInfo&ord,const QListitemData(ordermode->currentIndex()).toInt(); if(omode==ORDERNONE)return; + resetModel(); MTGetOrderList ol=req->queryGetOrderList(oldestOrderStamp()); if(ol.hasError()){ QMessageBox::warning(this,tr("Warning"),tr("There was a problem retrieving the order list: %1").arg(ol.errorString())); @@ -253,42 +255,32 @@ void MOrdersTab::orderByEvent() } void MOrdersTab::orderByCustomer() -{/*TODO +{ //display selection dialog - MCustomerListDialog mcl(req,this,true); + MCustomerListDialog mcl(this,true); //wait for user if(mcl.exec()!=QDialog::Accepted) return; //get selection - MCustomer cst=mcl.getCustomer(); - if(!cst.isValid()){ + MOCustomerInfo cst=mcl.getCustomer(); + if(cst.customerid().isNull()){ qDebug("nothing selected"); return; } - qint64 custid=cst.customerID(); //request data and display - //TODO: unify this part with updateOrders - ordermodel->clear(); - ordermodel->setHorizontalHeaderLabels(QStringList()< orders=req->getAllOrders(); + resetModel(); + MTGetOrdersByCustomer obc=req->queryGetOrdersByCustomer(cst.customerid(),oldestOrderStamp()); + if(obc.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error while retrieving order list: %1").arg(obc.errorString())); + return; + } + QList orders=obc.getorders(); if(orders.size()==0)return; - QList cust=req->getAllCustomers(); - int cl=0; + QList cust;cust<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++; + addOrderToModel(orders[i],cust); } - ordermode->setCurrentIndex(ordermode->count()-1);*/ + ordermode->setCurrentIndex(ordermode->count()-1); } void MOrdersTab::orderByOrder() diff --git a/wob/customer.wolf b/wob/customer.wolf index edac499..120f926 100644 --- a/wob/customer.wolf +++ b/wob/customer.wolf @@ -55,12 +55,16 @@ + + + + + - @@ -71,11 +75,32 @@ + + + + + + + + + + + + + + + + + + + + + @@ -84,17 +109,46 @@ + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + @@ -117,6 +171,7 @@ + @@ -124,8 +179,16 @@ + + + + + + + + \ No newline at end of file diff --git a/wob/order.wolf b/wob/order.wolf index 9036fe4..152e92e 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -279,7 +279,7 @@ - + diff --git a/woc/phpout.cpp b/woc/phpout.cpp index 5f17b2a..83679f4 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -706,7 +706,7 @@ QString WocPHPServerOut::classMappings(const WocClass&cls) code+="\nstatic public function fromTable"+k[i]+"($table){\n"; code+="\t$data=new WO"+cls.name()+"();\n"; QMapmap=cls.mapping(k[i]); - QStringList mapk=map.keys(); + QStringList mapk=cls.mappingProperties(k[i]); for(int j=0;j WocClass::mapping(QString m)const return ret; } +QStringList WocClass::mappingProperties(QString m)const +{ + if(!m_maps.contains(m))return QStringList(); + QList sml=m_maps[m]; + QStringList ret; + for(int i=0;i mapping(QString m)const; /**returns the method for a specific mapping or an empty string if it does not exist in the specified language*/ diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 14bd2af..ea91db8 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -92,6 +92,16 @@ class WOOrderInfo extends WOOrderInfoAbstract $trans->setcustomers(self::getCustomerListByOrders($olst)); } + /**called from GetOrdersByCustomer transaction*/ + static public function getOrdersByCustomer($trans) + { + $cid=$trans->getcustomerid(); + $old=$trans->getoldest(); + if($old===false)$old=0; + global $db; + $trans->setorders(self::fromTableArrayorder(WTorder::selectFromDB("customerid=".$db->escapeInt($cid)." AND ordertime>=".$db->escapeInt($old),"ORDER BY orderid"))); + } + /**helper function for several transactions: selects customers by their IDs references by the given order info objects*/ static protected function getCustomerListByOrders(array $olist) {