make order comments changeable
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 11 Nov 2008 16:12:01 +0000 (16:12 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 11 Nov 2008 16:12:01 +0000 (16:12 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@177 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

doc/prog_protocol.html
src/order.cpp
src/order.h
src/orderwin.cpp
src/orderwin.h
www/inc/classes/order.php
www/machine.php

index 802ce33..7c04ecf 100644 (file)
@@ -568,6 +568,16 @@ The <tt>orderbyticket</tt> transaction can be used to find an order by a ticket
 
 The <tt>getordersbyevents</tt> transaction can be used to return all orders that contain tickets for a specific event. The request is a space separated list of event IDs, the response has the format of the <tt>getorderlist</tt> response.
 
+<h3>Changing the Comment of an Order</h3>
+
+The <tt>setordercomment</tt> transaction is used to change the orders comment. The request is a simple XML document:<p>
+
+<pre>
+&lt;OrderComment orderid="id">comment text...&lt;/OrderComment>
+</pre>
+
+The response body is empty or optionally contains an error message.
+
 <!-- ************************************************************************************
      ************************************************************************************
      ************************************************************************************ -->
index 354d856..2ce1178 100644 (file)
@@ -461,6 +461,26 @@ bool MOrder::shipOrder()
        return r;
 }
 
+bool MOrder::sendComment(QString nc)
+{
+       //make sure we are in a sane state
+       makeComplete();
+       if(!req || m_orderid<0)return false;
+       //create XML
+       QDomDocument doc;
+       QDomElement root=doc.createElement("OrderComment");
+       root.setAttribute("orderid",m_orderid);
+       root.appendChild(doc.createTextNode(nc));
+       doc.appendChild(root);
+       //request
+       if(!req->request("setordercomment",doc.toByteArray()))return false;
+       if(req->responseStatus()==MWebRequest::Ok){
+               m_comment=nc;
+               return true;
+       }else
+               return false;
+}
+
 
 /******************************************************************************
  * Ticket
index fb41e2c..2454822 100644 (file)
@@ -320,6 +320,9 @@ class MOrder
                
                /**mark the order as shipped; queries DB; returns true on success*/
                bool shipOrder();
+               
+               /**set a new comment and immediately send it to the server (will not set the comment if the server rejects it); returns whether setting was successful*/
+               bool sendComment(QString);
        
        private:
                MWebRequest*req;
index 227aba2..3e8570c 100644 (file)
@@ -33,6 +33,7 @@
 #include <QPushButton>
 #include <QStandardItemModel>
 #include <QTableView>
+#include <QTextEdit>
 
 #include <math.h>
 
@@ -59,6 +60,8 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o)
         ->setEnabled(req->hasRole("changeticketprice"));
        m->addAction(tr("&Return Ticket..."),this,SLOT(ticketReturn()))
         ->setEnabled(req->hasRole("ticketreturn"));
+       m->addAction(tr("Change Commen&t..."),this,SLOT(changeComment()))
+        ->setEnabled(req->hasRole("setordercomment"));
        m->addSeparator();
        m->addAction(tr("&Close"),this,SLOT(close()));
        m=mb->addMenu(tr("&Payment"));
@@ -105,7 +108,7 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o)
        gl->addWidget(new QLabel(tr("Order State:")),++rw,0);
        gl->addWidget(m_state=new QLabel(m_order.orderStatusString()),rw,1);
        gl->addWidget(new QLabel(tr("Order Comment:")),++rw,0);
-       gl->addWidget(lab=new QLabel(m_order.comment()),rw,1);
+       gl->addWidget(m_comment=lab=new QLabel(m_order.comment()),rw,1);
        lab->setWordWrap(true);
        gl->setColumnStretch(0,0);
        gl->setColumnStretch(1,10);
@@ -479,6 +482,34 @@ void MOrderWindow::shipOrder()
        }
 }
 
+void MOrderWindow::changeComment()
+{
+       //create editor dialog
+       QString cmt=m_order.comment();
+       QDialog d;
+       d.setWindowTitle(tr("Set comment: order %1").arg(m_order.orderID()));
+       QVBoxLayout*vl;
+       d.setLayout(vl=new QVBoxLayout);
+       QTextEdit*te;
+       vl->addWidget(te=new QTextEdit,1);
+       te->setPlainText(cmt);
+       vl->addSpacing(15);
+       QHBoxLayout*hl;
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addStretch(10);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("&Save")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+       hl->addWidget(p=new QPushButton(tr("&Cancel")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+       //get status
+       if(d.exec()!=QDialog::Accepted)return;
+       //send to server
+       m_order.sendComment(cmt=te->toPlainText());
+       //reset display
+       m_comment->setText(cmt);
+}
+
 /*************************************************************************************/
 
 MTicketView::MTicketView(QWidget*w,QList<MTicket>t)
index 16243ad..5c7acd1 100644 (file)
@@ -69,6 +69,9 @@ class MOrderWindow:public QMainWindow
                /**return a ticket*/
                void ticketReturn();
                
+               /**change the comment on the order*/
+               void changeComment();
+               
                /**cancel the order*/
                void cancelOrder();
                /**mark as shipped*/
@@ -84,7 +87,7 @@ class MOrderWindow:public QMainWindow
                MWebRequest*req;
                MOrder m_order;
                bool m_changed;
-               QLabel *m_orderid,*m_orderdate,*m_sentdate,*m_state,*m_paid,*m_total;
+               QLabel *m_orderid,*m_orderdate,*m_sentdate,*m_state,*m_paid,*m_total,*m_comment;
                QTableView *m_tickettable;
                QStandardItemModel *m_ticketmodel;
 };
index 231e7da..8610f3c 100644 (file)
@@ -744,4 +744,29 @@ function orderByEventXml($events)
                getOrderListXml("orderid IN (".$olst.")");
        }
 }
+
+//change the comment on an order
+function setOrderCommentXml($txt)
+{
+       //parse XML data
+       $xml=new DomDocument;
+       $xml->loadXml($txt);
+       $doc=$xml->documentElement;
+       $oid=$doc->getAttribute("orderid")+0;
+       $comment="";
+       foreach($doc->childNodes as $cn)
+               if($cn->nodeType==XML_TEXT_NODE)
+                       $comment=$cn->wholeText;
+       //set comment
+       global $db;
+       $db->beginTransaction();
+       $upcnt=$db->update("order",array("comments"=>$comment),"orderid=".$db->escapeInt($oid));
+       $db->commitTransaction();
+       if($upcnt!==false)
+               header("X-MagicSmoke-Status: Ok");
+       else{
+               header("X-MagicSmoke-Status: Error");
+               echo "Unable to update order comment.";
+       }
+}
 ?>
\ No newline at end of file
index a85bcdd..7423f1d 100644 (file)
@@ -23,7 +23,7 @@ $ALLOWEDREQUESTS=array(
        tr("geteventlist"),tr("geteventdata"),tr("seteventdata"),tr("eventsummary"),tr("cancelevent"),//event infos
        tr("getroomdata"),tr("setroomdata"),//room infos
        tr("getcustomerlist"),tr("getcustomer"),tr("setcustomer"), //customer info
-       tr("checkorder"),tr("createorder"),tr("createsale"),tr("getorderlist"),tr("getorder"),tr("orderpay"),tr("orderrefund"),tr("ordershipped"),tr("cancelorder"),tr("orderbyticket"),tr("getordersbyevents"), //sell/order stuff
+       tr("checkorder"),tr("createorder"),tr("createsale"),tr("getorderlist"),tr("getorder"),tr("orderpay"),tr("orderrefund"),tr("ordershipped"),tr("cancelorder"),tr("orderbyticket"),tr("getordersbyevents"),tr("setordercomment"), //sell/order stuff
        tr("getticket"),tr("useticket"),tr("changeticketprice"),tr("ticketreturn"),//ticket management
        tr("gettemplatelist"),tr("gettemplate"),tr("settemplate") //templates
 );
@@ -321,6 +321,10 @@ if($SMOKEREQUEST=="getordersbyevents"){
        orderByEventXml(trim($REQUESTDATA));
        exit();
 }
+if($SMOKEREQUEST=="setordercomment"){
+       setOrderCommentXml(trim($REQUESTDATA));
+       exit();
+}
 
 //get a ticket
 if($SMOKEREQUEST=="getticket"){