reservation to order
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 16:11:01 +0000 (16:11 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 16:11:01 +0000 (16:11 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@388 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/orderwin.cpp
src/dialogs/orderwin.h
wob/order.wolf
www/inc/wext/order.php

index 6e6fdea..d4c5338 100644 (file)
@@ -815,33 +815,18 @@ void MOrderWindow::cancelOrder()
                m_state->setText(m_order.orderStatusString());*/
 }
 
-void MOrderWindow::createOrder(Create mode)
-{/*TODO
-       MOrder ord;
-       //handle reservation changes specially
-       if(m_order.orderStatus()==MOrder::Reserved){
-               bool ok=false;
-               ord=m_order;
-               switch(mode){
-                       case CreateOrder:ok=ord.reservationToOrder();break;
-                       case CreateSale:ok=ord.reservationToSale();break;
-                       default:ok=false;
-               }
-               if(!ok)return;
-       }else{
-               //handle case of new order
-               switch(mode){
-                       case CreateSale:ord=m_order.createSale();break;
-                       case CreateOrder:ord=m_order.createOrder();break;
-                       case CreateReservation:ord=m_order.createReservation();break;
-               }
-               if(!ord.isValid())return;
+void MOrderWindow::createOrder()
+{
+       //sanity check
+       if(m_order.status()!=MOOrder::Reserved)return;
+       //call server
+       MTReservationToOrder ro=req->queryReservationToOrder(m_order.orderid());
+       if(ro.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Error while changing order status: %1").arg(ro.errorString()));
+               return;
        }
-       //display final order
-       MOrderWindow *ow=new MOrderWindow(parentWidget(),req,ord);
-       ow->show();
-       //undisplay self
-       close();*/
+       m_order=ro.getorder();
+       updateData();
 }
 
 void MOrderWindow::shipOrder()
index 663281f..8d40e82 100644 (file)
@@ -33,10 +33,6 @@ class MOrderWindow:public QMainWindow
                /**creates the order window*/
                MOrderWindow(QWidget*,const MOOrder&);
        
-       private:
-               /**helper enum for create* methods*/
-               enum Create{CreateOrder,CreateSale,CreateReservation};
-               
        private slots:
                /**internal: updates the labels and the ticket table*/
                void updateData();
@@ -90,8 +86,8 @@ class MOrderWindow:public QMainWindow
                /**mark as shipped*/
                void shipOrder();
                
-               /**create a new order*/
-               void createOrder(Create mode=CreateOrder);
+               /**create a new order from a reservation*/
+               void createOrder();
                
        private:
                MOOrder m_order;
index 2016357..c6cbefb 100644 (file)
        
        <Transaction name="CreateOrder"/>
        <Transaction name="CreateReservation"/>
-       <Transaction name="ReservationToOrder"/>
+       <Transaction name="ReservationToOrder">
+               <Input>
+                       <Var name="orderid" type="int"/>
+               </Input>
+               <Call lang="php" method="WOOrder::reservation2Order($this);"/>
+               <Output>
+                       <Var name="order" type="Order"/>
+               </Output>
+       </Transaction>
        <Transaction name="CancelOrder"/>
        <Transaction name="OrderPay">
                <Input>
index b17875b..718cc9e 100644 (file)
@@ -377,6 +377,27 @@ class WOOrder extends WOOrderAbstract
                $trans->setorder(WOOrder::fromTableorder($ord));
                $trans->setamount($pay);
        }
+       
+       /**called from the ReservationToOrder transaction*/
+       public static function reservation2Order($trans)
+       {
+               //get order
+               $ord=WTorder::getFromDB($trans->getorderid());
+               if($ord===false){
+                       $trans->abortWithError(tr("Invalid Order ID."));
+                       return;
+               }
+               //check state
+               if($ord->status != WTorder::Reserved){
+                       $trans->abortWithError(tr("This order is not a reservation."));
+                       return;
+               }
+               //change state
+               $ord->status = WTorder::Sold;
+               $ord->update();
+               //return
+               $trans->setorder(WOOrder::fromTableorder($ord));
+       }
 };
 
 ?>
\ No newline at end of file