*checkorder: sale-only and order-only tickets are now in sufficient quantity to finis...
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 17 Nov 2008 17:56:56 +0000 (17:56 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 17 Nov 2008 17:56:56 +0000 (17:56 +0000)
*make erroneous order continue-able

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

src/order.cpp
src/order.h
src/orderwin.cpp
src/orderwin.h
www/inc/classes/order.php

index 2ce1178..3f94850 100644 (file)
@@ -286,6 +286,28 @@ void MOrder::makeComplete()
        getFromDB(m_orderid);
 }
 
+void MOrder::pruneInvalid()
+{
+       //tickets
+       QList<MTicket>ntc;
+       for(int i=0;i<m_tickets.size();i++)
+               switch(m_tickets[i].status()){
+                       case MTicket::CheckFailTooLate:
+                       case MTicket::CheckFailExhausted:
+                       case MTicket::CheckFailCancelled:
+                       case MTicket::CheckFailEventInvalid:
+                       case MTicket::Invalid:
+                               //ignore
+                               break;
+                       default:
+                               //keep all others
+                               ntc.append(m_tickets[i]);
+               }
+       m_tickets=ntc;
+       //TODO: vouchers
+       //TODO: shipping info?
+}
+
 /**************
  * below this line we need to make sure the order is completed before we return results
  */
index 2454822..7ac4301 100644 (file)
@@ -323,6 +323,9 @@ class MOrder
                
                /**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);
+               
+               /**if the order is in check state yet: prune invalid objects*/
+               void pruneInvalid();
        
        private:
                MWebRequest*req;
index 0bf2915..9f85363 100644 (file)
@@ -50,6 +50,7 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o)
         ->setEnabled(req->hasRole("createorder")&&o.canOrder());
        m->addAction(tr("&Sell..."),this,SLOT(createSale()))
         ->setEnabled(req->hasRole("createsale")&&o.canSell());
+       m->addAction(tr("&Prune and recheck..."),this,SLOT(recheckOrder()));
        m->addSeparator();
        m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()))
         ->setEnabled(req->hasRole("cancelorder")&&o.isStored());
@@ -467,12 +468,26 @@ void MOrderWindow::createOrder(bool issale)
        close();
 }
 
-
 void MOrderWindow::createSale()
 {
        createOrder(true);
 }
 
+void MOrderWindow::recheckOrder()
+{
+       //prune
+       m_order.pruneInvalid();
+       //now check
+       MOrder ord;
+       ord=m_order.createOrder("checkorder");
+       if(!ord.isValid())return;
+       //display final order
+       MOrderWindow *ow=new MOrderWindow(parentWidget(),req,ord);
+       ow->show();
+       //undisplay self
+       close();
+}
+
 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){
index 5c7acd1..49492a8 100644 (file)
@@ -82,6 +82,9 @@ class MOrderWindow:public QMainWindow
                
                /**create a sale*/
                void createSale();
+               
+               /**prune and recheck the order*/
+               void recheckOrder();
        
        private:
                MWebRequest*req;
index 8610f3c..65fbd5c 100644 (file)
@@ -241,6 +241,7 @@ class Order
                                continue;
                        }
                        $stime=$evt->getStartTime();
+                       $etime=$evt->getEndTime();
                        $estat="ok";
                        //check whether we can still order
                        if(($stime-$orderstop)<=$curtime){
@@ -253,7 +254,7 @@ class Order
                                }
                        }
                        //check whether we can still sell
-                       if(($stime-$salestop)<=$curtime){
+                       if(($etime-$salestop)<=$curtime){
                                if($estat=="ok")$estat="orderonly";
                                else $estat="toolate";
                                //if this is a sale: can't do it
@@ -263,8 +264,13 @@ class Order
                                                return false;
                                }
                        }
-                       //create matching error XML for order/sale failure
+                       //set order state
                        if($estat!="ok"){
+                               if($ostat=="ok")$ostat=$estat;
+                               else if($ostat!=$estat)$ostat="fail";
+                       }
+                       //create matching error XML for total order+sale failure
+                       if($estat=="toolate"){
                                //create only one ticket and make it sound negative
                                $ev=$xml->createElement("Ticket");
                                $ev->setAttribute("event",$evid);
@@ -273,8 +279,6 @@ class Order
                                if($estat!="toolate")
                                        $ev->setAttribute("price",$evt->getDefaultPrice());
                                $ord->appendChild($ev);
-                               if($ostat=="ok")$ostat=$estat;
-                               else if($ostat!=$estat)$ostat="fail";
                                continue;
                        }
                        //check whether event is cancelled
@@ -293,11 +297,11 @@ class Order
                        $avail=$evt->availableTicketAmount();
                        if($avail<$amount){
                                if($dumpxml===false)return false;
-                               //create a few good ones
+                               //create a few (semi-)good ones
                                for($i=0;$i<$avail;$i++){
                                        $ev=$xml->createElement("Ticket");
                                        $ev->setAttribute("event",$evid);
-                                       $ev->setAttribute("status","ok");
+                                       $ev->setAttribute("status",$estat);
                                        $ev->setAttribute("price",$evt->getDefaultPrice());
                                        $ev->setAttribute("id",$ftid++);
                                        $ord->appendChild($ev);
@@ -309,14 +313,15 @@ class Order
                                $ev->setAttribute("status","exhausted");
                                $ev->setAttribute("id",$ftid++);
                                $ord->appendChild($ev);
+                               $ostat="fail";
                                $ret=false;
                                continue;
                        }
-                       //survived all tests: finally create good tickets
+                       //survived all tests: finally create (semi-)good tickets
                        for($i=0;$i<$amount;$i++){
                                $ev=$xml->createElement("Ticket");
                                $ev->setAttribute("event",$evid);
-                               $ev->setAttribute("status","ok");
+                               $ev->setAttribute("status",$estat);
                                $ev->setAttribute("price",$evt->getDefaultPrice());
                                $ev->setAttribute("id",$ftid++);
                                $ord->appendChild($ev);
@@ -326,6 +331,8 @@ class Order
                
                //TODO: check vouchers
                
+               //TODO: check shipping
+               
                //add other data and dump XML
                if($dumpxml){
                        $ord->appendChild($xml->createElement("DeliveryAddress",$this->deliveryaddress));