*implement cancel order
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 30 Mar 2008 16:04:52 +0000 (16:04 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 30 Mar 2008 16:04:52 +0000 (16:04 +0000)
*implement ship order

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@151 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 e5ea315..17232e7 100644 (file)
@@ -554,6 +554,14 @@ The <tt>getorderlist</tt> transaction can be used to get a list of all currently
 
 The <tt>orderpay</tt> transaction is used to add to the amount paid in an order. The <tt>orderrefund</tt> transaction is used to subtract from the amount paid of an order. In both cases the request consists of two positive numbers separated by a space: the order-ID and the amount in cent. The response contains the new amount paid after the transaction in the case of success and status error plus an explanation in case of any problem.
 
+<h3>Set Shipping State of an Order</h3>
+
+The <tt>ordershipped</tt> transaction is used to mark an order as shipped. This transaction is only legal for orders in the "placed" state. The request contains the order ID, the response contains the new shipping time (set automatically during transaction).
+
+<h3>Cancelling an Order</h3>
+
+The <tt>cancelorder</tt> transaction is used to mark an order as cancelled. It also marks all tickets inside the order as cancelled and voids any vouchers in it. This transaction is only legal for orders in the "placed" state.
+
 <!-- ************************************************************************************
      ************************************************************************************
      ************************************************************************************ -->
index 940a140..901fc08 100644 (file)
@@ -428,6 +428,26 @@ MOrder MOrder::createSale()
        return createOrder("createsale");
 }
 
+bool MOrder::cancelOrder()
+{
+       if(!req->request("cancelorder",QByteArray::number(m_orderid)))return false;
+       bool r=req->responseStatus()==MWebRequest::Ok;
+       if(r)m_status=Cancelled;
+       return r;
+}
+
+bool MOrder::shipOrder()
+{
+       if(!req->request("ordershipped",QByteArray::number(m_orderid)))return false;
+       bool r=req->responseStatus()==MWebRequest::Ok;
+       if(r){
+               m_status=Sent;
+               m_stime=req->responseBody().trimmed().toInt();
+       }
+       return r;
+}
+
+
 /******************************************************************************
  * Ticket
  ******************************************************************************/
index 16902ce..05818c5 100644 (file)
@@ -305,6 +305,12 @@ class MOrder
                
                /**create a sale in the DB; returns it*/
                MOrder createSale();
+               
+               /**cancel the order; queries DB; returns true on success*/
+               bool cancelOrder();
+               
+               /**mark the order as shipped; queries DB; returns true on success*/
+               bool shipOrder();
        
        private:
                MWebRequest*req;
index 828f53e..3463d2f 100644 (file)
@@ -50,8 +50,10 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o)
        m->addAction(tr("&Sell..."),this,SLOT(createSale()))
         ->setEnabled(req->hasRole("createsale")&&o.canSell());
        m->addSeparator();
-       m->addAction(tr("C&ancel Order..."))
+       m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()))
         ->setEnabled(req->hasRole("cancelorder")&&o.isStored());
+       m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder()))
+        ->setEnabled(req->hasRole("ordershipped"));
        m->addSeparator();
        m->addAction(tr("Ch&ange Ticket-Price..."),this,SLOT(changeTicket()))
         ->setEnabled(req->hasRole("changeticketprice"));
@@ -202,11 +204,20 @@ void MOrderWindow::printTickets(QList<MTicket> tickets)
 
 void MOrderWindow::printBill()
 {
+       //get template
        QString tf=req->getTemplate("bill.odtt");
        if(tf==""){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (bill.odtt). Giving up."));
                return;
        }
+       //mark order as shipped?
+       if(m_order.orderStatus()==MOrder::Placed)
+       if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
+               m_order.shipOrder();
+               m_state->setText(m_order.orderStatusString());
+               m_sentdate->setText(m_order.sentDateTimeStr());
+       }
+       //print bill
        MOdtSignalRenderer rend(tf);
        connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&)));
        connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&)));
@@ -216,11 +227,13 @@ void MOrderWindow::printBill()
 
 void MOrderWindow::saveBill()
 {
+       //get template
        QString tf=req->getTemplate("eventsummary.odtt");
        if(tf==""){
                QMessageBox::warning(this,tr("Warning"),tr("Unable to get template file (eventsummary.odtt). Giving up."));
                return;
        }
+       //get target file name
        QFileDialog fd(this);
        fd.setAcceptMode(QFileDialog::AcceptSave);
        fd.setFileMode(QFileDialog::AnyFile);
@@ -233,6 +246,14 @@ void MOrderWindow::saveBill()
                if(fn.size()<1)return;
                fname=fn[0];
        }
+       //mark order as shipped?
+       if(m_order.orderStatus()==MOrder::Placed)
+       if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
+               m_order.shipOrder();
+               m_state->setText(m_order.orderStatusString());
+               m_sentdate->setText(m_order.sentDateTimeStr());
+       }
+       //render bill
        MOdtSignalRenderer rend(tf);
        connect(&rend,SIGNAL(getVariable(QString,QString&)),this,SLOT(getVariable(QString,QString&)));
        connect(&rend,SIGNAL(getLoopIterations(QString,int&)),this,SLOT(getLoopIterations(QString,int&)));
@@ -355,7 +376,17 @@ void MOrderWindow::changeTicket()
 }
 
 void MOrderWindow::cancelOrder()
-{}
+{
+       if(QMessageBox::question(this,tr("Cancel Order?"),tr("Cancel this order now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)!=QMessageBox::Yes)return;
+       if(m_order.orderStatus()!=MOrder::Placed){
+               QMessageBox::warning(this,tr("Warning"),tr("Cannot cancel this order: it is in the wrong state."));
+               return;
+       }
+       if(!m_order.cancelOrder()){
+               QMessageBox::warning(this,tr("Warning"),tr("Failed to cancel this order."));
+       }else
+               m_state->setText(m_order.orderStatusString());
+}
 
 void MOrderWindow::createOrder(bool issale)
 {
@@ -376,6 +407,15 @@ void MOrderWindow::createSale()
        createOrder(true);
 }
 
+void MOrderWindow::shipOrder()
+{
+       if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
+               m_order.shipOrder();
+               m_state->setText(m_order.orderStatusString());
+               m_sentdate->setText(m_order.sentDateTimeStr());
+       }
+}
+
 /*************************************************************************************/
 
 MTicketView::MTicketView(QWidget*w,QList<MTicket>t)
index 549ad7f..8a2c5fe 100644 (file)
@@ -69,6 +69,8 @@ class MOrderWindow:public QMainWindow
                
                /**cancel the order*/
                void cancelOrder();
+               /**mark as shipped*/
+               void shipOrder();
                
                /**create a new order*/
                void createOrder(bool issale=false);
index 12357be..ad17315 100644 (file)
@@ -75,6 +75,12 @@ class Order
        {
                return $this->orderid!==false;
        }
+       
+       /**returns the sent time as unix timestamp*/
+       public function getSentTime()
+       {
+               return $this->senttime;
+       }
 
        /**removes all items from the given Cart and enters them into itself; returns false if some items cannot be ordered or the order is already closed*/
        public function emptyCart($cart)
@@ -384,6 +390,31 @@ class Order
                if($totalprice<$this->amountpaid)return "needrefund";
                else return "needpayment";
        }
+       
+       /**sets the order to being shipped, returns true on success*/
+       public function setShipped()
+       {
+               if(!$this->isValid())return false;
+               if($this->status!=ORDER_PLACED)return false;
+               global $db;
+               $this->senttime=time();
+               $db->update("order",array("status"=>ORDER_SENT,"senttime"=>$this->senttime),"orderid=".$db->escapeInt($this->orderid));
+               return true;
+       }
+       
+       /**sets the order to being cancelled, returns true on success*/
+       public function setCancelled()
+       {
+               if(!$this->isValid())return false;
+               if($this->status!=ORDER_PLACED)return false;
+               global $db;
+               $db->update("order",array("status"=>ORDER_CANCELLED,"senttime"=>time()),"orderid=".$db->escapeInt($this->orderid));
+               //propagate to tickets
+               $db->update("ticket",array("status"=>TICKET_CANCELLED),"orderid=".$db->escapeInt($this->orderid));
+               //TODO: propagate to vouchers
+               
+               return true;
+       }
 };
 
 function createOrderXml($xmldata,$action)
@@ -546,4 +577,54 @@ function orderPayXml($data,$factor)
        echo $amt2;
 }
 
+//mark order as shipped
+function orderShippedXml($oid)
+{
+       if(!is_numeric($oid)){
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Order ID must be numeric."));
+       }
+       $oid=$oid+0;
+       if($oid<0){
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Order ID is invalid."));
+       }
+       $ord=new Order($oid);
+       if(!$ord->isValid()){
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Order ID is invalid."));
+       }
+       if($ord->setShipped()){
+               header("X-MagicSmoke-Status: Ok");
+               print($ord->getSentTime());
+       }else{
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Wrong state, cannot set order to shipped."));
+       }
+}
+
+//mark order as cancelled
+function orderCancelXml($oid)
+{
+       if(!is_numeric($oid)){
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Order ID must be numeric."));
+       }
+       $oid=$oid+0;
+       if($oid<0){
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Order ID is invalid."));
+       }
+       $ord=new Order($oid);
+       if(!$ord->isValid()){
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Order ID is invalid."));
+       }
+       if($ord->setCancelled()){
+               header("X-MagicSmoke-Status: Ok");
+       }else{
+               header("X-MagicSmoke-Status: Error");
+               die(tr("Wrong state, cannot set order to cancelled."));
+       }
+}
 ?>
\ No newline at end of file
index cd8cb2a..b66d17c 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"), //sell/order stuff
+       tr("checkorder"),tr("createorder"),tr("createsale"),tr("getorderlist"),tr("getorder"),tr("orderpay"),tr("orderrefund"),tr("ordershipped"),tr("cancelorder"), //sell/order stuff
        tr("getticket"),tr("useticket"),tr("changeticketprice"),//ticket management
        tr("gettemplatelist"),tr("gettemplate"),tr("settemplate") //templates
 );
@@ -302,6 +302,16 @@ if($SMOKEREQUEST=="orderrefund"){
        orderPayXml($REQUESTDATA,-1);
        exit();
 }
+//mark order shipped
+if($SMOKEREQUEST=="ordershipped"){
+       orderShippedXml(trim($REQUESTDATA));
+       exit();
+}
+//cancel order
+if($SMOKEREQUEST=="cancelorder"){
+       orderCancelXml(trim($REQUESTDATA));
+       exit();
+}
 
 //get a ticket
 if($SMOKEREQUEST=="getticket"){