From 20b7e24f9e6acb397ff683177b41d332df212e33 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Thu, 29 Dec 2011 10:45:04 +0100 Subject: [PATCH] issue #48 - can change order addresses now --- pack | 2 +- src/dialogs/customerdlg.cpp | 48 ++++++++++++++++++++++++++++++++++---- src/dialogs/customerdlg.h | 25 ++++++++++++++++---- src/dialogs/orderwin.cpp | 38 ++++++++++++++++++++++++++++++ src/dialogs/orderwin.h | 5 ++++ wob/db/user.wolf | 2 + wob/transact/order.wolf | 15 ++++++++++++ www/inc/wext/order.php | 53 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 177 insertions(+), 11 deletions(-) diff --git a/pack b/pack index f40058f..6a565ed 160000 --- a/pack +++ b/pack @@ -1 +1 @@ -Subproject commit f40058f8f817598e0533e9c57c6a4a0d3517afd9 +Subproject commit 6a565edd00675310f956428a83791b8ba3f16a7b diff --git a/src/dialogs/customerdlg.cpp b/src/dialogs/customerdlg.cpp index b3839ab..328f83d 100644 --- a/src/dialogs/customerdlg.cpp +++ b/src/dialogs/customerdlg.cpp @@ -645,6 +645,16 @@ void MAddressListWidget::preselect(int i) widget()->adjustSize(); } +void MAddressListWidget::preselect(const MOAddress& addr) +{ + for(int i=0;iaddLayout(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(); +} diff --git a/src/dialogs/customerdlg.h b/src/dialogs/customerdlg.h index 97f77bf..4342654 100644 --- a/src/dialogs/customerdlg.h +++ b/src/dialogs/customerdlg.h @@ -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: QListm_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*/ diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index 1268312..347e61e 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -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(); diff --git a/src/dialogs/orderwin.h b/src/dialogs/orderwin.h index 402a795..a8861bf 100644 --- a/src/dialogs/orderwin.h +++ b/src/dialogs/orderwin.h @@ -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*/ diff --git a/wob/db/user.wolf b/wob/db/user.wolf index 60ebd2c..0768b14 100644 --- a/wob/db/user.wolf +++ b/wob/db/user.wolf @@ -123,6 +123,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/wob/transact/order.wolf b/wob/transact/order.wolf index 892da40..8b37434 100644 --- a/wob/transact/order.wolf +++ b/wob/transact/order.wolf @@ -321,6 +321,21 @@ the order that ownes the changed ticket, in case this is called from the order window + + + Mildly privileged users: change the delivery and/or invoice address of an order. + + the ID of the order, this is mandatory + if true: the value in invoiceaddr is actually used, if false: the invoice address is left unchanged + the ID of the invoice address, <0 for deleting the invoice address + if true: the value in deliveryaddr is actually used, if false: the delivery address is left unchanged + the ID of the delivery address, <0 for deleting the delivery address + + + + the order after the change has become active. + + Returns a list of all shipping methods that the user has access to. This transaction is sensitive to flags, like "anyshipping". diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 1c37823..6594835 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -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 -- 1.7.2.5