implemented marking as shipped
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Wed, 30 Dec 2009 20:06:10 +0000 (20:06 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Wed, 30 Dec 2009 20:06:10 +0000 (20:06 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@380 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

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

index 4a6f118..8cd7c5f 100644 (file)
@@ -60,7 +60,7 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o)
        m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()))
         ->setEnabled(req->hasRight(req->RCancelOrder));
        m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder()))
-        ->setEnabled(req->hasRole("ordershipped"));
+        ->setEnabled(req->hasRight(req->ROrderMarkShipped));
        m->addSeparator();
        m->addAction(tr("Ch&ange Item-Price..."),this,SLOT(changeItem()))
         ->setEnabled(req->hasRole("changeticketprice"));
@@ -866,10 +866,10 @@ void MOrderWindow::createOrder(Create mode)
 }
 
 void MOrderWindow::shipOrder()
-{/*TODO
+{
        if(QMessageBox::question(this,tr("Mark as shipped?"),tr("Mark this order as shipped now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)==QMessageBox::Yes){
                QDateTime tm=QDateTime::currentDateTime();
-               if(req->hasRole("_explicitshipdate")){
+               if(req->hasRight(req->POrderMarkShipped_SetTime)){
                        QDialog d;
                        d.setWindowTitle(tr("Set shipping time"));
                        QHBoxLayout*hl;
@@ -890,10 +890,15 @@ void MOrderWindow::shipOrder()
                        if(d.exec()!=QDialog::Accepted)return;
                        tm=dte->dateTime();
                }
-               m_order.shipOrder(tm);
+               MTOrderMarkShipped ms=req->queryOrderMarkShipped(m_order.orderid(),tm.toTime_t());
+               if(ms.hasError()){
+                       QMessageBox::warning(this,tr("Warning"),tr("Error while marking order as shipped: %1").arg(ms.errorString()));
+                       return;
+               }
+               m_order=ms.getorder();
                m_state->setText(m_order.orderStatusString());
                m_sentdate->setText(m_order.sentDateTimeStr());
-       }*/
+       }
 }
 
 void MOrderWindow::changeComment()
index e706bae..70cd756 100644 (file)
                </Output>
        </Transaction>
        
+       <Transaction name="OrderMarkShipped">
+               <Privilege name="SetTime"/>
+               <Input>
+                       <Var name="orderid" type="int">The order to be marked</Var>
+                       <Var name="shiptime" type="int64">The time when it was shipped. If the user does not have the SetTime privilege or if this property is &lt;=0 the current date/time is set instead.</Var>
+               </Input>
+               <Call lang="php" method="WOOrder::markAsShipped($this);"/>
+               <Output>
+                       <Var name="order" type="Order">a fresh copy of the changed order</Var>
+               </Output>
+       </Transaction>
+       
        <Transaction name="GetAllShipping">
                <Input/>
                <Call lang="php" method="$this->setshipping(WOShipping::fromTableArrayshipping(WTshipping::selectFromDB()));"/>
index 8e03f00..8a60598 100644 (file)
@@ -190,6 +190,38 @@ class WOOrder extends WOOrderAbstract
                //return order
                $trans->setorder(WOOrder::fromTableorder($ord));
        }
+       
+       /**called from the OrderMarkShipped transaction*/
+       public static function markAsShipped($trans)
+       {
+               //get order
+               $ord=WTorder::getFromDB($trans->getorderid());
+               if($ord===false){
+                       $trans->abortWithError(tr("Order ID is not valid."));
+                       return;
+               }
+               if($ord->senttime !== null && $ord->senttime > 0){
+                       $trans->abortWithError(tr("Order has already been shipped."));
+                       return;
+               }
+               if($ord->status != WTorder::Placed){
+                       $trans->abortWithError(tr("Order is in the wrong state."));
+                       return;
+               }
+               //get timestamp
+               $tm=time();
+               if($trans->havePrivilege(WtrOrderMarkShipped::Priv_SetTime)){
+                       $tmt=$trans->getshiptime();
+                       if($tmt!==false && $tmt >0)
+                               $tm=$tmt;
+               }
+               //update
+               $ord->senttime=$tm;
+               $ord->status=WTorder::Sent;
+               $ord->update();
+               //return
+               $trans->setorder(WOOrder::fromTableorder($ord));
+       }
 };
 
 ?>
\ No newline at end of file