issue #48 - can change order addresses now
authorKonrad Rosenbaum <konrad@silmor.de>
Thu, 29 Dec 2011 09:45:04 +0000 (10:45 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Thu, 29 Dec 2011 09:45:04 +0000 (10:45 +0100)
pack
src/dialogs/customerdlg.cpp
src/dialogs/customerdlg.h
src/dialogs/orderwin.cpp
src/dialogs/orderwin.h
wob/db/user.wolf
wob/transact/order.wolf
www/inc/wext/order.php

diff --git a/pack b/pack
index f40058f..6a565ed 160000 (submodule)
--- a/pack
+++ b/pack
@@ -1 +1 @@
-Subproject commit f40058f8f817598e0533e9c57c6a4a0d3517afd9
+Subproject commit 6a565edd00675310f956428a83791b8ba3f16a7b
index b3839ab..328f83d 100644 (file)
@@ -645,6 +645,16 @@ void MAddressListWidget::preselect(int i)
        widget()->adjustSize();
 }
 
+void MAddressListWidget::preselect(const MOAddress& addr)
+{
+       for(int i=0;i<m_addr.size();i++){
+               if(m_addr[i].addressid()==addr.addressid()){
+                       preselect(i);
+                       break;
+               }
+       }
+}
+
 void MAddressListWidget::createAddress()
 {
        MAddressDialog d(this);
@@ -775,7 +785,7 @@ void MAddressDialog::selectCountry()
 MAddressChoiceDialog::MAddressChoiceDialog(QWidget*par,const MOCustomer&c)
        :QDialog(par),m_cust(c)
 {
-       m_needupdate=false;
+       m_needupdate=m_unsel=false;
        setWindowTitle(tr("Chose an Address"));
        QHBoxLayout*hl;
        QVBoxLayout*vl;
@@ -786,9 +796,9 @@ MAddressChoiceDialog::MAddressChoiceDialog(QWidget*par,const MOCustomer&c)
        connect(m_lwidget,SIGNAL(addressCreated(const MOAddress&)),this,SLOT(changed()));
        connect(m_lwidget,SIGNAL(addressEdited(const MOAddress&)),this,SLOT(changed()));
        //on selection: first update customer, then close window
-       connect(m_lwidget,SIGNAL(addressSelected(qint64)),this,SLOT(updateCustomer()),Qt::DirectConnection);
+       connect(m_lwidget,SIGNAL(addressSelected(qint64)), this,SLOT(updateCustomer()), Qt::DirectConnection);
        
-       vl->addLayout(hl=new QHBoxLayout,0);
+       vl->addLayout(m_btnlayout=hl=new QHBoxLayout,0);
        hl->addStretch(10);
        QPushButton*p;
        hl->addWidget(p=new QPushButton(tr("Add Address")),0);
@@ -798,8 +808,25 @@ MAddressChoiceDialog::MAddressChoiceDialog(QWidget*par,const MOCustomer&c)
        connect(p,SIGNAL(clicked()),this,SLOT(reject()));
 }
 
-MOAddress MAddressChoiceDialog::address()const{return m_lwidget->selection();}
-qint64 MAddressChoiceDialog::addressId()const{return m_lwidget->selection().addressid();}
+void MAddressChoiceDialog::addUnselectButton(const QString& t)
+{
+       m_btnlayout->insertSpacing(2,20);
+       QPushButton*p;
+       m_btnlayout->insertWidget(3,p=new QPushButton(t));
+       connect(p,SIGNAL(clicked()),this,SLOT(unselect()));
+}
+
+MOAddress MAddressChoiceDialog::address()const
+{
+       if(m_unsel)return MOAddress();
+       else return m_lwidget->selection();
+}
+
+qint64 MAddressChoiceDialog::addressId()const
+{
+       if(m_unsel)return -1;
+       else return address().addressid();
+}
 void MAddressChoiceDialog::changed(){m_needupdate=true;}
 
 void MAddressChoiceDialog::updateCustomer()
@@ -818,3 +845,14 @@ void MAddressChoiceDialog::updateCustomer()
        //close dialog successfully
        accept();
 }
+
+void MAddressChoiceDialog::preselect(const MOAddress& addr)
+{
+       m_lwidget->preselect(addr);
+}
+
+void MAddressChoiceDialog::unselect()
+{
+       m_unsel=true;
+       accept();
+}
index 97f77bf..4342654 100644 (file)
@@ -23,6 +23,7 @@
 #include "MOCustomerInfo"
 #include "MOCustomer"
 
+class QHBoxLayout;
 class QLineEdit;
 class QListView;
 class QSortFilterProxyModel;
@@ -163,6 +164,9 @@ class MAddressListWidget:public QScrollArea
                /**pre-selects an address by its position in the current address list, this method should only be called once!*/
                void preselect(int);
                
+               ///alias: pre-selects an address if it is present in the list of displayed addresses
+               void preselect(const MOAddress&);
+               
        private slots:
                /**internal: used to change an address after editing*/
                void addrEdit(int);
@@ -170,8 +174,11 @@ class MAddressListWidget:public QScrollArea
                /**internal: used to remember the selected address*/
                void addrSel(const MOAddress&);
                
-               /**internal: add an address widget, if the boolean is true it is also made visible*/
-               void addAddr(const MOAddress&,bool v=false);
+               /**internal: add an address widget, 
+               \param vis if true the routine ensures the widget is in the visible part of the scrollarea
+               \param mark if true marks the address with a color
+               */
+               void addAddr(const MOAddress&,bool vis=false);
                
        private:
                QList<MOAddress>m_addr;
@@ -189,23 +196,31 @@ class MAddressChoiceDialog:public QDialog
                /**creates the dialog*/
                MAddressChoiceDialog(QWidget*,const MOCustomer&);
                
-               /**returns the chosen address*/
+               /**returns the chosen address or an invalid address if none was chosen*/
                MOAddress address()const;
                
-               /**returns the ID of the chosen address*/
+               /**returns the ID of the chosen address or -1 if the unselect button was used*/
                qint64 addressId()const;
                
                /**returns the (modified) customer object*/
                MOCustomer customer()const{return m_cust;}
+       public slots:
+               ///pre-select an address
+               void preselect(const MOAddress&);
+               ///add an unselect button
+               void addUnselectButton(const QString&);
        private slots:
                /**internal: notified if there is a change to the address list*/
                void changed();
                /**internal: updates the customer if necessary*/
                void updateCustomer();
+               ///unselect button pressed
+               void unselect();
        private:
                MOCustomer m_cust;
-               bool m_needupdate;
+               bool m_needupdate,m_unsel;
                MAddressListWidget*m_lwidget;
+               QHBoxLayout*m_btnlayout;
 };
 
 /**dialog for editing exactly one address*/
index 1268312..347e61e 100644 (file)
@@ -19,6 +19,7 @@
 #include "ticketrender.h"
 #include "msinterface.h"
 #include "templates.h"
+#include "customerdlg.h"
 
 #include "MOEvent"
 
@@ -97,12 +98,17 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o)
         ->setEnabled(req->hasRight(req->RChangeTicketPriceCategory));
        m->addAction(tr("&Return Item..."),this,SLOT(itemReturn()))
         ->setEnabled(req->hasRight(req->RReturnTicketVoucher));
+       m->addSeparator();
        m->addAction(tr("Add Commen&t..."),this,SLOT(addComment()))
         ->setEnabled(req->hasRight(req->ROrderAddComment));
        if(req->hasRight(req->ROrderChangeComments))
         m->addAction(tr("Change C&omments..."),this,SLOT(changeComments()));
        m->addAction(tr("Change Sh&ipping Method..."),this,SLOT(changeShipping()))
         ->setEnabled(req->hasRight(req->ROrderChangeShipping));
+       m->addAction(tr("Change Invoice Address..."),this,SLOT(changeInvAddr()))
+        ->setEnabled(req->hasRight(req->RChangeOrderAddress));
+       m->addAction(tr("Change Delivery Address..."),this,SLOT(changeDelAddr()))
+        ->setEnabled(req->hasRight(req->RChangeOrderAddress));
        m->addSeparator();
        m->addAction(tr("&Close"),this,SLOT(close()));
        
@@ -1029,6 +1035,38 @@ void MOrderWindow::changeShipping()
        updateData();
 }
 
+void MOrderWindow::changeDelAddr()
+{
+       //get customer
+       MAddressChoiceDialog d(this,m_order.customer().value());
+       d.preselect(m_order.deliveryaddress());
+       d.addUnselectButton(tr("No Delivery Address"));
+       if(d.exec()!=QDialog::Accepted)return;
+       //send data
+       MTChangeOrderAddress oa=req->queryChangeOrderAddress(m_order.orderid(), false,-1, true,d.addressId());
+       if(oa.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Unable to set address, server error: %1").arg(oa.errorString()));
+               return;
+       }
+       m_daddr->setText(d.address().fullAddress());
+}
+
+void MOrderWindow::changeInvAddr()
+{
+       //get customer
+       MAddressChoiceDialog d(this,m_order.customer().value());
+       d.preselect(m_order.invoiceaddress());
+       d.addUnselectButton(tr("No Invoice Address"));
+       if(d.exec()!=QDialog::Accepted)return;
+       //send data
+       MTChangeOrderAddress oa=req->queryChangeOrderAddress(m_order.orderid(), true,d.addressId(), false,-1);
+       if(oa.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Unable to set address, server error: %1").arg(oa.errorString()));
+               return;
+       }
+       m_iaddr->setText(d.address().fullAddress());
+}
+
 void MOrderWindow::voucherAudit()
 {
        QModelIndexList lst=m_table->selectionModel()->selectedIndexes();
index 402a795..a8861bf 100644 (file)
@@ -84,6 +84,11 @@ class MOrderWindow:public QMainWindow
                /**change the shipping option*/
                void changeShipping();
                
+               ///change the invoice address
+               void changeInvAddr();
+               ///change the delivery address
+               void changeDelAddr();
+               
                /**cancel the order*/
                void cancelOrder();
                /**mark as shipped*/
index 60ebd2c..0768b14 100644 (file)
                <Preset><V col="rolename" val="OrderAdvanced"/><V col="rightname" val="OrderRefund"/></Preset>
                <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="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="ReturnTicketVoucher:ReturnPastTicket"/></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="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>
index 892da40..8b37434 100644 (file)
                        <Var name="order" type="Order">the order that ownes the changed ticket, in case this is called from the order window</Var>
                </Output>
        </Transaction>
+
+       <Transaction name="ChangeOrderAddress">
+               <Doc>Mildly privileged users: change the delivery and/or invoice address of an order.</Doc>
+               <Input>
+                       <Var name="orderid" type="int">the ID of the order, this is mandatory</Var>
+                       <Var name="setinvoiceaddr" type="bool">if true: the value in invoiceaddr is actually used, if false: the invoice address is left unchanged</Var>
+                       <Var name="invoiceaddr" type="int">the ID of the invoice address, &lt;0 for deleting the invoice address</Var>
+                       <Var name="setdeliveryaddr" type="bool">if true: the value in deliveryaddr is actually used, if false: the delivery address is left unchanged</Var>
+                       <Var name="deliveryaddr" type="int">the ID of the delivery address, &lt;0 for deleting the delivery address</Var>
+               </Input>
+               <Call lang="php" method="WOOrder::changeAddress($this);"/>
+               <Output>
+                       <Var name="order" type="Order">the order after the change has become active.</Var>
+               </Output>
+       </Transaction>
        
        <Transaction name="GetAllShipping" updating="no">
                <Doc>Returns a list of all shipping methods that the user has access to. This transaction is sensitive to flags, like "anyshipping".</Doc>
index 1c37823..6594835 100644 (file)
@@ -746,6 +746,59 @@ class WOOrder extends WOOrderAbstract
                //send mail
                mail($ct->email,$subject,$mailtext,$mailheader);
        }
+       
+       ///change the addresses on the order, called by ChangeOrderAddress transaction
+       static public function changeAddress($trans)
+       {
+               global $db;
+               $oid=$trans->getorderid();
+               $ord=WTorder::getFromDB($oid);
+               if(!is_a($ord,"WTorder")){
+                       $trans->abortWithError(tr("Order does not exist."));
+                       return;
+               }
+               //invoice address
+               $cid=$ord->customerid;
+               if($trans->getsetinvoiceaddr()){
+                       $iad=$trans->getinvoiceaddr();
+                       if($iad<0){
+                               $ord->invoiceaddress=null;
+                       }else{
+                               $addr=WTaddress::getFromDB($iad);
+                               if(!is_a($addr,"WTaddress")){
+                                       $trans->abortWithError(tr("Invalid address ID"));
+                                       return;
+                               }
+                               if($addr->customerid!=$cid){
+                                       $trans->abortWithError(tr("Address does not match customer."));
+                                       return;
+                               }
+                               $ord->invoiceaddress=$iad;
+                       }
+               }
+               //same with delivery address
+               if($trans->getsetdeliveryaddr()){
+                       $dad=$trans->getdeliveryaddr();
+                       if($dad<0){
+                               $ord->deliveryaddress=null;
+                       }else{
+                               $addr=WTaddress::getFromDB($dad);
+                               if(!is_a($addr,"WTaddress")){
+                                       $trans->abortWithError(tr("Invalid address ID"));
+                                       return;
+                               }
+                               if($addr->customerid!=$cid){
+                                       $trans->abortWithError(tr("Address does not match customer."));
+                                       return;
+                               }
+                               $ord->deliveryaddress=$dad;
+                       }
+               }
+               //send to DB
+               $ord->update();
+               //fetch and deliver result
+               $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($oid)/*$ord*/));
+       }
 };
 
 ?>
\ No newline at end of file