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))
}
void MOrderWindow::itemReturn()
-{/*TODO
- if(!m_order.isValid())return;
+{
//get ticket selection
QModelIndexList lst=m_table->selectionModel()->selectedIndexes();
if(lst.size()<1)return;
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()
<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()));"/>
//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