From 8930c44b54f43576d1dfee4961de5909e726962e Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 1 Jan 2010 17:34:41 +0000 Subject: [PATCH] cancel order git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@391 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dialogs/orderwin.cpp | 17 +++++----- wob/order.wolf | 18 ++++++++-- www/inc/wext/order.php | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 12 deletions(-) diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index f89385c..c80d394 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -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() diff --git a/wob/order.wolf b/wob/order.wolf index 9cc972a..70edefd 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -419,7 +419,17 @@ - + + Users with this privilege can also cancel orders that have already been shipped + Users with this privilege can cancel orders with tickets in the past (unless they have been used). + + + + + + + + The order to be paid @@ -460,7 +470,7 @@ Changes the shipping option and/or price of an order - + Users with this privilege can set arbitrary shipping prices, all others are limited to the default price of the shipping method. The order to be changed the new shipping option or -1 if shipping is to be deleted @@ -473,7 +483,7 @@ - + Users with this privilege can set a time for when the order was shipped, for all others the current time is used. The order to be marked The time when it was shipped. If the user does not have the SetTime privilege or if this property is <=0 the current date/time is set instead. @@ -508,7 +518,7 @@ - + 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. barcode of the ticket or voucher diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index ea51648..1bec613 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -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 -- 1.7.2.5