return tickets/vouchers
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 16:48:46 +0000 (16:48 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 1 Jan 2010 16:48:46 +0000 (16:48 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@389 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

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

index d4c5338..f89385c 100644 (file)
@@ -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
-               QList<MTicket>tickets=m_order.tickets();
-               MTicket tick;
-               for(int i=0;i<tickets.size();i++)
-                       if(tickets[i].ticketID()==id)
-                               tick=tickets[i];
-               if(!tick.isValid())return;
-               //check state
-               if(tick.status()!=MTicket::Bought && tick.status()!=MTicket::Reserved){
-                       QMessageBox::warning(this,tr("Warning"),tr("This ticket cannot be returned, it has already been used or is in the wrong state."));
-                       return;
-               }
-               //ask nicely
-               if(QMessageBox::question(this,tr("Return Ticket"),tr("Do you really want to return this ticket?"),QMessageBox::Yes|QMessageBox::No)!=QMessageBox::Yes)return;
-               //submit
-               QString r=m_order.ticketReturn(tick.ticketID());
-               m_total->setText(m_order.totalPriceString());
-               updateTable();
-               if(r!="")QMessageBox::warning(this,tr("Warning"),trUtf8(r.toUtf8()));
-       }else
-       if(type==ITEM_VOUCHER){
-               //find ticket
-               QList<MVoucher>vouchers=m_order.vouchers();
-               MVoucher vou;
-               for(int i=0;i<vouchers.size();i++)
-                       if(vouchers[i].voucherID()==id)
-                               vou=vouchers[i];
-               if(!vou.isValid())return;
-               //check state
-               if(vou.isUsed()){
-                       QMessageBox::warning(this,tr("Warning"),tr("This voucher cannot be returned, it has already been used."));
-                       return;
-               }
-               //ask nicely
-               if(QMessageBox::question(this,tr("Return Voucher"),tr("Do you really want to return this voucher?"),QMessageBox::Yes|QMessageBox::No)!=QMessageBox::Yes)return;
-               //submit
-               QString r=m_order.voucherReturn(vou.voucherID());
-               m_total->setText(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()
index c6cbefb..9cc972a 100644 (file)
@@ -95,7 +95,7 @@
                        <Value name="MaskPay" value="0x200"> <!--dec: 512-->
                        Masking value: if this bit is set the ticket must be paid by the customer.</Value>
                        <Value name="MaskUsable" value="0x300"> <!--dec: 768-->
-                       Masking value: combines Block+Pay - the ticket can be used to watch a show.</Value>
+                       Masking value: combines Block+Pay - the ticket can be used to watch a show or is already being used.</Value>
                        <Value name="MaskReturnable" value="0x10"> <!--dec: 16-->
                        Masking value: if this bit is set the ticket can still be cancelled.</Value>
                </Column>
                </Output>
        </Transaction>
        <Transaction name="OrderChangeComments">
-               <Doc>For privileges users: edit the complete comments field, overwrite it.</Doc>
+               <Doc>For privileged users: edit the complete comments field, overwrite it.</Doc>
                <Input>
                        <Var name="orderid" type="int">the order to be commented upon</Var>
                        <Var name="comments" type="string">the comments</Var>
                </Output>
        </Transaction>
        
+       <Transaction name="ReturnTicketVoucher">
+               <Privilege name="ReturnPastTicket"/>
+               <Input>
+                       <Var name="barcode" type="astring">barcode of the ticket or voucher</Var>
+               </Input>
+               <Call lang="php" method="WOOrder::returnTicketVoucher($this);"/>
+               <Output>
+                       <Var name="order" type="Order">the order that owned the returned object, in case this is called from the order window</Var>
+               </Output>
+       </Transaction>
+       
        <Transaction name="GetAllShipping">
                <Input/>
                <Call lang="php" method="$this->setshipping(WOShipping::fromTableArrayshipping(WTshipping::selectFromDB()));"/>
index 718cc9e..ea51648 100644 (file)
@@ -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