*implement find order by customer
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 29 Dec 2009 17:08:54 +0000 (17:08 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 29 Dec 2009 17:08:54 +0000 (17:08 +0000)
*correction: make sure mappings are translated in order

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@368 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/customerdlg.cpp
src/dialogs/customerdlg.h
src/iface/customer.h
src/mwin/orderstab.cpp
wob/customer.wolf
wob/order.wolf
woc/phpout.cpp
woc/processor.cpp
woc/processor.h
www/inc/wext/order.php

index c15affa..dc04e8f 100644 (file)
@@ -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();
-       QList<MOCustomerShort>cl=gac.getcustomers();
-       //FIXME
-//     for(int i=0;i<cl.size();i++)
-//             m_list.append(cl[i]);
+       m_list=gac.getcustomers();
        //update widget
        m_listmodel->clear();
        m_listmodel->insertRows(0,m_list.size());
        m_listmodel->insertColumn(0);
        for(int i=0;i<m_list.size();i++){
                QModelIndex idx=m_listmodel->index(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();
-       */
 }
 
 
index cc242f2..abf04d6 100644 (file)
@@ -17,7 +17,7 @@
 #include <QDialog>
 #include <QList>
 
-#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<MCustomer> m_list;
+               QList<MOCustomerInfo> 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
 {
index 55c7589..7048fe8 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <QString>
 
-#include "MOCustomerShort.h"
+// #include "MOCustomerShort.h"
 #include "MOCustomer.h"
 
 /**this class expands on MOCustomer to add some convenience methods*/
index d5f4dd3..009b688 100644 (file)
@@ -16,6 +16,8 @@
 #include "msinterface.h"
 #include "orderwin.h"
 
+#include "customerdlg.h"
+
 #include "orderstab.h"
 
 #include <QBoxLayout>
@@ -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 QList<MOCustomerInf
 
 void MOrdersTab::updateOrders()
 {
-       resetModel();
        int omode=ordermode->itemData(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()<<tr("Status")<<tr("Total")<<tr("Paid")<<tr("Customer"));
-       QList<MOrder> 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<MOOrderInfo> orders=obc.getorders();
        if(orders.size()==0)return;
-       QList<MCustomer> cust=req->getAllCustomers();
-       int cl=0;
+       QList<MOCustomerInfo> cust;cust<<cst;
        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++;
+               addOrderToModel(orders[i],cust);
        }
-       ordermode->setCurrentIndex(ordermode->count()-1);*/
+       ordermode->setCurrentIndex(ordermode->count()-1);
 }
 
 void MOrdersTab::orderByOrder()
index edac499..120f926 100644 (file)
        <Class name="Country">
                <Property name="id" type="astring"/>
                <Property name="name" type="astring"/>
+               <Mapping table="country">
+                       <Map property="id" column="countryid"/>
+                       <Map property="name" column="countryname"/>
+               </Mapping>
        </Class>
        <Class name="Address">
                <Property name="addressid" type="int64"/>
                <Property name="customerid" type="int32"/>
+               <Property name="lastused" type="int64"/>
                <Property name="name" type="string"/>
-               <Property name="company" type="string"/>
                <Property name="addr1" type="string"/>
                <Property name="addr2" type="string"/>
                <Property name="city" type="string"/>
                
                <Property name="country" type="Country"/>
                
+               <Mapping table="address">
+                       <Map column="addressid"/>
+                       <Map column="customerid"/>
+                       <Map column="lastused"/>
+                       <Map column="name"/>
+                       <Map column="addr1"/>
+                       <Map column="addr2"/>
+                       <Map column="city"/>
+                       <Map column="state"/>
+                       <Map column="zipcode"/>
+                       <Map column="countryid"/>
+                       <Map column="isdeleted"/>
+                       <Map property="country">
+                               <Call lang="php" method="WOCountry::fromTablecountry(WTcountry::getFromDB($table->countryid))"/>
+                       </Map>
+               </Mapping>
        </Class>
        <Class name="ContactType">
                <Property name="contacttypeid" type="int32"/>
                <Property name="contacttype" type="string"/>
                <Property name="uriprefix" type="string"/>
+               <Mapping table="contacttype">
+                       <Map column="contacttypeid"/>
+                       <Map column="contacttype"/>
+                       <Map column="uriprefix"/>
+               </Mapping>
        </Class>
        <Class name="Contact">
                <Property name="contactid" type="int64"/>
                <Property name="contact" type="string"/>
                
                <Property name="contacttype" type="ContactType"/>
+               
+               <Mapping table="contact">
+                       <Map column="contactid"/>
+                       <Map column="customerid"/>
+                       <Map column="contacttypeid"/>
+                       <Map column="contact"/>
+                       <Map property="contacttype">
+                               <Call lang="php" method="WOContactType::fromTablecontacttype(WTcontacttype::getFromDB($table->contacttypeid))"/>
+                       </Map>
+               </Mapping>
        </Class>
        <Class name="Customer">
                <Property name="id" type="int"/>
+               <Property name="title" type="string"/>
+               <Property name="firstname" type="string"/>
                <Property name="name" type="string"/>
                <Property name="comments" type="string"/>
+               <Property name="flags" type="string"/>
                <!--online login data-->
                <Property name="email" type="string"/>
-               <Property name="passwd" type="string"/>
+               <!-- password is never sent from server to client -->
                
                <Property name="addresses" type="List:Address"/>
                <Property name="contacts" type="List:Contact"/>
+               
+               <Mapping table="customer">
+                       <Map column="customerid" property="id"/>
+                       <Map column="title"/>
+                       <Map column="firstname"/>
+                       <Map column="name"/>
+                       <Map column="comments"/>
+                       <Map column="flags"/>
+                       <Map column="email"/>
+                       <Map property="addresses">
+                               <Call lang="php" method="WOAddress::fromTableArrayaddress(WTaddress::selectFromDB('customerid='.$GLOBALS['db']->escapeInt($table->customerid)))"/>
+                       </Map>
+                       <Map property="contacts">
+                               <Call lang="php" method="WOContact::fromTableArraycontact(WTcontact::selectFromDB('customerid='.$GLOBALS['db']->escapeInt($table->customerid)))"/>
+                       </Map>
+               </Mapping>
        </Class>
        <Class name="CustomerInfo" abstract="yes">
                <!-- abstract is needed on C++ side -->
                <Input>
                        <Var name="customerid" type="int"/>
                </Input>
+               <Call lang="php" method="$this->setcustomer(WOCustomer::fromTablecustomer(WTcustomer::getFromDB($this->getcustomerid())));"/>
                <Output>
                        <Var name="customer" type="Customer"/>
                </Output>
        
        <Transaction name="GetAllCustomerNames">
                <Input/>
+               <Call lang="php" method="$this->setcustomers(WOCustomerInfo::fromTableArraycustomer(WTcustomer::selectFromDB()));"/>
                <Output>
                        <Var name="customers" type="List:CustomerInfo"/>
                </Output>
        </Transaction>
+       
+       <Transaction name="DeleteCustomer">
+               <Input>
+                       <Var name="customerid" type="int"/>
+                       <Var name="mergewithid" type="int"/>
+               </Input>
+       </Transaction>
 </Wolf>
\ No newline at end of file
index 9036fe4..152e92e 100644 (file)
                                <Call lang="php" method="$data->getTotalPriceFromDB()"/>
                        </Map>
                        <Map property="amountdue">
-                               <Call lang="php" method="$data->prop_amountdue=$data->prop_totalprice - $data->propamountpaid"/>
+                               <Call lang="php" method="$data->prop_amountdue=$data->prop_totalprice - $data->prop_amountpaid"/>
                        </Map>
                        <Map property="amounttickets">
                                <Call lang="php" method="$data->getAmountTicketsFromDB()"/>
index 5f17b2a..83679f4 100644 (file)
@@ -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";
                QMap<QString,QString>map=cls.mapping(k[i]);
-               QStringList mapk=map.keys();
+               QStringList mapk=cls.mappingProperties(k[i]);
                for(int j=0;j<mapk.size();j++){
                        QString meth=cls.mapMethod(k[i],mapk[j],"php");
                        if(meth!="")code+="\t$data->prop_"+mapk[j]+"="+meth+";\n";
index 9c68500..576af3c 100644 (file)
@@ -588,6 +588,16 @@ QMap<QString,QString> WocClass::mapping(QString m)const
        return ret;
 }
 
+QStringList WocClass::mappingProperties(QString m)const
+{
+       if(!m_maps.contains(m))return QStringList();
+       QList<s_map> sml=m_maps[m];
+       QStringList ret;
+       for(int i=0;i<sml.size();i++)
+               ret<<sml[i].property;
+       return ret;
+}
+
 QString WocClass::mapMethod(QString table,QString property,QString lang)const
 {
        if(!m_maps.contains(table))return "";
index ea03796..d318ec9 100644 (file)
@@ -102,6 +102,8 @@ class WocClass
                bool hasMapping(QString m)const{return m_maps.contains(m);}
                /**returns the names of all tables for which a mapping exists*/
                QStringList mappingTables()const{return m_maps.keys();}
+               /**returns the (correctly ordered) properties for a mapping*/
+               QStringList mappingProperties(QString)const;
                /**returns the specific mapping; map key=property, map value=column*/
                QMap<QString,QString> mapping(QString m)const;
                /**returns the method for a specific mapping or an empty string if it does not exist in the specified language*/
index 14bd2af..ea91db8 100644 (file)
@@ -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)
        {