From 1d80945d31a56a2e3f5e62a013676d9ccc6aab51 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 1 Jan 2010 16:48:46 +0000 Subject: [PATCH] return tickets/vouchers git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@389 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/dialogs/orderwin.cpp | 62 ++++++++++++---------------------------------- wob/order.wolf | 15 +++++++++- www/inc/wext/order.php | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 48 deletions(-) diff --git a/src/dialogs/orderwin.cpp b/src/dialogs/orderwin.cpp index d4c5338..f89385c 100644 --- a/src/dialogs/orderwin.cpp +++ b/src/dialogs/orderwin.cpp @@ -61,7 +61,7 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o) m->addAction(tr("Ch&ange Item-Price..."),this,SLOT(changeItem())) ->setEnabled(req->hasRole("changeticketprice")); m->addAction(tr("&Return Item..."),this,SLOT(itemReturn())) - ->setEnabled(req->hasRole("ticketreturn")); + ->setEnabled(req->hasRight(req->RReturnTicketVoucher)); m->addAction(tr("Add Commen&t..."),this,SLOT(addComment())) ->setEnabled(req->hasRight(req->ROrderAddComment)); if(req->hasRight(req->ROrderChangeComments)) @@ -748,8 +748,7 @@ void MOrderWindow::changeItem() } void MOrderWindow::itemReturn() -{/*TODO - if(!m_order.isValid())return; +{ //get ticket selection QModelIndexList lst=m_table->selectionModel()->selectedIndexes(); if(lst.size()<1)return; @@ -757,49 +756,20 @@ void MOrderWindow::itemReturn() QString id=m_model->data(idx).toString(); if(id=="")return; int type=m_model->data(idx,Qt::UserRole).toInt(); - if(type==ITEM_TICKET){ - //find ticket - QListtickets=m_order.tickets(); - MTicket tick; - for(int i=0;isetText(m_order.totalPriceString()); - updateTable(); - if(r!="")QMessageBox::warning(this,tr("Warning"),trUtf8(r.toUtf8())); - }else - if(type==ITEM_VOUCHER){ - //find ticket - QListvouchers=m_order.vouchers(); - MVoucher vou; - for(int i=0;isetText(m_order.totalPriceString()); - updateTable(); - if(r!="")QMessageBox::warning(this,tr("Warning"),trUtf8(r.toUtf8())); - }else - QMessageBox::warning(this,tr("Warning"),tr("Cannot return this item type."));*/ + if(type!=ITEM_TICKET && type!=ITEM_VOUCHER){ + QMessageBox::warning(this,tr("Warning"),tr("Cannot return this item type.")); + return; + } + //ask nicely + if(QMessageBox::question(this,tr("Return Ticket or Voucher"),tr("Do you really want to return this ticket or voucher?"),QMessageBox::Yes|QMessageBox::No)!=QMessageBox::Yes)return; + //submit + MTReturnTicketVoucher rtv=req->queryReturnTicketVoucher(id); + if(rtv.hasError()){ + QMessageBox::warning(this,tr("Warning"),tr("Error whily trying to return item: %1").arg(rtv.errorString())); + return; + } + m_order=rtv.getorder(); + updateData(); } void MOrderWindow::cancelOrder() diff --git a/wob/order.wolf b/wob/order.wolf index c6cbefb..9cc972a 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -95,7 +95,7 @@ Masking value: if this bit is set the ticket must be paid by the customer. - Masking value: combines Block+Pay - the ticket can be used to watch a show. + Masking value: combines Block+Pay - the ticket can be used to watch a show or is already being used. Masking value: if this bit is set the ticket can still be cancelled. @@ -496,7 +496,7 @@ - For privileges users: edit the complete comments field, overwrite it. + For privileged users: edit the complete comments field, overwrite it. the order to be commented upon the comments @@ -507,6 +507,17 @@ + + + + barcode of the ticket or voucher + + + + the order that owned the returned object, in case this is called from the order window + + + diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 718cc9e..ea51648 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -398,6 +398,52 @@ class WOOrder extends WOOrderAbstract //return $trans->setorder(WOOrder::fromTableorder($ord)); } + + /**called from the ReturnTicketVoucher transaction*/ + public static function returnTicketVoucher($trans) + { + //find ticket + $obj=WTticket::getFromDB($trans->getbarcode()); + if($obj!==false){ + //verify ticket has not been used and is not in the past + if(($obj->status & WTticket::MaskReturnable)==0){ + $trans->abortWithError(tr("This ticket cannot be returned!")); + return; + } + $event=WTevent::getFromDB($obj->eventid); + if($event === false){ + $trans->abortWithError(tr("Internal error: ticket for unknown event.")); + return; + } + if($event->starttime < time() && !$trans->havePrivilege(WtrReturnTicketVoucher::Priv_ReturnPastTicket)){ + $trans->abortWithError(tr("This ticket is for a past event and you do not have the privilege to return it.")); + return; + } + //return it + $obj->status = WTticket::Cancelled; + $obj->update(); + }else{ + //find voucher + $obj=WTvoucher::getFromDB($trans->getbarcode()); + if($obj!==false){ + //verify voucher has not been used yet + if($obj->isused){ + $trans->abortWithError(tr("This voucher has already been used, cannot return it.")); + return; + } + //return it + $obj->price=0; + $obj->value=0; + $obj->update(); + }else{ + //nothing found + $trans->abortWithError(tr("Ticket or voucher not found.")); + return; + }} + + //return fresh order object + $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($obj->orderid))); + } }; ?> \ No newline at end of file -- 1.7.2.5