cancel order
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 17:34:41 +0000 (17:34 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 17:34:41 +0000 (17:34 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@391 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

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

index f89385c..c80d394 100644 (file)
@@ -773,16 +773,17 @@ void MOrderWindow::itemReturn()
 }
 
 void MOrderWindow::cancelOrder()
-{/*TODO
-       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 && m_order.orderStatus()!=MOrder::Reserved){
-               QMessageBox::warning(this,tr("Warning"),tr("Cannot cancel this order: it is in the wrong state."));
+{
+       if(QMessageBox::question(this,tr("Cancel Order?"),tr("Cancel this order now?"),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes)!=QMessageBox::Yes)
+               return;
+       //query
+       MTCancelOrder co=req->queryCancelOrder(m_order.orderid());
+       if(co.hasError()){
+               QMessageBox::warning(this,tr("Warning"),tr("Error while cancelling order: %1").arg(co.errorString()));
                return;
        }
-       if(!m_order.cancelOrder()){
-               QMessageBox::warning(this,tr("Warning"),tr("Failed to cancel this order."));
-       }else
-               m_state->setText(m_order.orderStatusString());*/
+       m_order=co.getorder();
+       updateData();
 }
 
 void MOrderWindow::createOrder()
index 9cc972a..70edefd 100644 (file)
                        <Var name="order" type="Order"/>
                </Output>
        </Transaction>
-       <Transaction name="CancelOrder"/>
+       <Transaction name="CancelOrder">
+               <Privilege name="CancelSentOrder">Users with this privilege can also cancel orders that have already been shipped</Privilege>
+               <Privilege name="CancelPastTickets">Users with this privilege can cancel orders with tickets in the past (unless they have been used).</Privilege>
+               <Input>
+                       <Var name="orderid" type="int"/>
+               </Input>
+               <Call lang="php" method="WOOrder::cancelOrder($this);"/>
+               <Output>
+                       <Var name="order" type="Order"/>
+               </Output>
+       </Transaction>
        <Transaction name="OrderPay">
                <Input>
                        <Var name="orderid" type="int">The order to be paid</Var>
        
        <Transaction name="OrderChangeShipping">
                <Doc>Changes the shipping option and/or price of an order</Doc>
-               <Privilege name="ChangePrice"/>
+               <Privilege name="ChangePrice">Users with this privilege can set arbitrary shipping prices, all others are limited to the default price of the shipping method.</Privilege>
                <Input>
                        <Var name="orderid" type="int">The order to be changed</Var>
                        <Var name="shippingid" type="int">the new shipping option or -1 if shipping is to be deleted</Var>
        </Transaction>
        
        <Transaction name="OrderMarkShipped">
-               <Privilege name="SetTime"/>
+               <Privilege name="SetTime">Users with this privilege can set a time for when the order was shipped, for all others the current time is used.</Privilege>
                <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>
        </Transaction>
        
        <Transaction name="ReturnTicketVoucher">
-               <Privilege name="ReturnPastTicket"/>
+               <Privilege name="ReturnPastTicket">Users with this privilege can return tickets for events in the past (if they have not been used yet). All others can only return tickets in the future.</Privilege>
                <Input>
                        <Var name="barcode" type="astring">barcode of the ticket or voucher</Var>
                </Input>
index ea51648..1bec613 100644 (file)
@@ -444,6 +444,85 @@ class WOOrder extends WOOrderAbstract
                //return fresh order object
                $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($obj->orderid)));
        }
+       
+       /**called from CancelOrder transaction*/
+       static public function cancelOrder($trans)
+       {
+               global $db;
+               //get order
+               $oid=$trans->getorderid();
+               $ord=WTorder::getFromDB($oid);
+               if($ord===false){
+                       $trans->abortWithError(tr("Invalid order ID."));
+                       return;
+               }
+               //verify order status
+               if($ord->status == WTorder::Cancelled){
+                       //ignore, already cancelled
+                       $trans->setorder(WOOrder::fromTableorder($ord));
+                       return;
+               }
+               //allow Placed/Reserved or Sent if privileged user
+               $ok = ($ord->status == WTorder::Placed || $ord->status == WTorder::Reserved ||
+                  ($ord->status == WTorder::Sent && $trans->havePrivilege(WtrCancelOrder::Priv_CancelSentOrder)));
+               if(!$ok){
+                       $trans->abortWithError(tr("The order is in the wrong status or you do not have the privilege to cancel it."));
+                       return;
+               }
+               
+               //get and verify tickets
+               $ticks=WTticket::selectFromDB("orderid=".$db->escapeInt($oid));
+               foreach($ticks as $tick){
+                       //ticket already cancelled?
+                       if($tick->status == WTticket::Cancelled)
+                               continue;
+                       //ticket not yet used?
+                       if(($tick->status & WTticket::MaskReturnable)==0){
+                               $trans->abortWithError(tr("This order contains a ticket that cannot be returned."));
+                               return;
+                       }
+                       //ticket in the past?
+                       $event=WTevent::getFromDB($tick->eventid);
+                       if($event === false){
+                               $trans->abortWithError(tr("Internal error: ticket for unknown event."));
+                               return;
+                       }
+                       if($event->starttime < time() && !$trans->havePrivilege(WtrCancelOrder::Priv_CancelPastTickets)){
+                               $trans->abortWithError(tr("This order contains a ticket that is for a past event and you do not have the privilege to cancel it."));
+                               return;
+                       }
+               }
+               //get and verify vouchers
+               $voucs=WTvoucher::selectFromDB("orderid=".$db->escapeInt($oid));
+               foreach($voucs as $vouc){
+                       //already used?
+                       if($vouc->isused){
+                               $trans->abortWithError(tr("This order contains a voucher that has already been used."));
+                               return;
+                       }
+               }
+               //TODO: get and verify items
+               
+               //return tickets
+               foreach($ticks as $tick){
+                       $tick->status = WTticket::Cancelled;
+                       $tick->update();
+               }
+               //return vouchers
+               foreach($voucs as $vouc){
+                       $vouc->price=0;
+                       $vouc->value=0;
+                       $vouc->update();
+               }
+               //TODO: return items
+               
+               //cancel order
+               $ord->status = WTorder::Cancelled;
+               $ord->update();
+               
+               //return
+               $trans->setorder(WOOrder::fromTableorder($ord));
+       }
 };
 
 ?>
\ No newline at end of file