MPriceCategoryDialog pcd(this);
if(pcd.exec()!=QDialog::Accepted)return;
MOPriceCategory cat=pcd.selection();
- //convert category into price
+ //sanity check on selectopm
if(cat.pricecategoryid().isNull())return;
+ for(int i=0;i<event.price().size();i++)
+ if(event.price().at(i).pricecategoryid()==cat.pricecategoryid()){
+ QMessageBox::warning(this,tr("Warning"),tr("Price category already exists in this event."));
+ return;
+ }
+ //convert category into price
MOEventPrice ep;
ep.setpricecategory(cat);
ep.setpricecategoryid(cat.pricecategoryid());
m_cancel=m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()));
m_ship=m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder()));
m->addSeparator();
- m->addAction(tr("Ch&ange Item-Price..."),this,SLOT(changeItem()))
+ m->addAction(tr("Change Item &Price..."),this,SLOT(changeItem()))
->setEnabled(req->hasRight(req->RChangeTicketPrice));
+ m->addAction(tr("C&hange Ticket Price Category..."),this,SLOT(changeItemCat()))
+ ->setEnabled(req->hasRight(req->RChangeTicketPriceCategory));
m->addAction(tr("&Return Item..."),this,SLOT(itemReturn()))
->setEnabled(req->hasRight(req->RReturnTicketVoucher));
m->addAction(tr("Add Commen&t..."),this,SLOT(addComment()))
m_model->setData(m_model->index(i,0),tickets[i].ticketid().value());
m_model->setData(m_model->index(i,0),ITEM_TICKET,Qt::UserRole);
m_model->setData(m_model->index(i,3),tickets[i].statusString());
- m_model->setData(m_model->index(i,4),tickets[i].priceString());
+ m_model->setData(m_model->index(i,4),tickets[i].priceString()+" ("+tickets[i].priceCategoryName()+")");
//find event
MOEvent ev;int eid=tickets[i].eventid();
for(int j=0;j<events.size();j++)
}
}
+void MOrderWindow::changeItemCat()
+{
+ //get ticket selection
+ QModelIndexList lst=m_table->selectionModel()->selectedIndexes();
+ if(lst.size()<1)return;
+ QModelIndex idx=m_model->index(lst[0].row(),0);
+ 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<MOTicket>tickets=m_order.tickets();
+ MOTicket tick;
+ for(int i=0;i<tickets.size();i++)
+ if(tickets[i].ticketid()==id)
+ tick=tickets[i];
+ //get event
+ MTGetEvent ge=MTGetEvent::query(tick.eventid());
+ if(ge.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error getting event, please try again."));
+ return;
+ }
+ MOEvent ev=ge.getevent();
+ //get Price Category
+ QList<MOEventPrice> ep=ev.price();
+ if(ep.size()<=1){
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot select another price category - there are none left."));
+ return;
+ }
+ int pcidx=0;
+ int pcid=tick.pricecategoryid();
+ QDialog d(this);
+ d.setWindowTitle(tr("Select Price Category"));
+ QVBoxLayout*vl;
+ QHBoxLayout*hl;
+ QComboBox*box;
+ QPushButton*p;
+ d.setLayout(vl=new QVBoxLayout);
+ vl->addWidget(new QLabel(tr("Please chose a price category:")));
+ vl->addWidget(box=new QComboBox);
+ for(int i=0;i<ep.size();i++){
+ box->addItem(ep[i].pricecategory().value().name().value()+": "+cent2str(ep[i].price()));
+ if(ep[i].pricecategoryid()==pcid)pcidx=i;
+ }
+ box->setCurrentIndex(pcidx);
+ box->setEditable(false);
+ vl->addSpacing(10);
+ vl->addStretch(10);
+ vl->addLayout(hl=new QHBoxLayout);
+ hl->addStretch(10);
+ hl->addWidget(p=new QPushButton(tr("Ok")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+ hl->addWidget(p=new QPushButton(tr("Cancel")));
+ connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+ if(d.exec()!=QDialog::Accepted)return;
+ pcidx=box->currentIndex();
+ //submit
+ MTChangeTicketPriceCategory ctp=req->queryChangeTicketPriceCategory(id,ep[pcidx].pricecategoryid());
+ if(ctp.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while attempting to change ticket price: %1").arg(ctp.errorString()));
+ return;
+ }
+ m_order=ctp.getorder();
+ updateData();
+ }else{
+ QMessageBox::warning(this,tr("Warning"),tr("Cannot change this item type."));
+ return;
+ }
+}
+
void MOrderWindow::itemReturn()
{
//get ticket selection
/**change a ticket/voucher price*/
void changeItem();
+ /**change a ticket price category*/
+ void changeItemCat();
/**return a ticket/voucher*/
void itemReturn();
//return whatever we have by now
return m_event;
}
+
+QString MOTicket::priceCategoryName()const
+{
+ return pricecategory().value().name();
+}
+QString MOTicket::priceCategoryShort()const
+{
+ return pricecategory().value().abbreviation();
+}
/**returns the ticket status as localized string*/
QString statusString()const{return TicketState2locstr(status());}
+ /**returns the full price category name*/
+ QString priceCategoryName()const;
+ /**returns the abbreviation for the price category*/
+ QString priceCategoryShort()const;
+
/**returns the event that this ticket belongs to - does a roundtrip to the database the first time this is called!*/
MOEvent event()const;
private:
<Property name="price" type="int"/>
<Property name="status" type="TicketState"/>
<Property name="orderid" type="int"/>
+ <Property name="pricecategoryid" type="int"/>
+ <Property name="pricecategory" type="PriceCategory"/>
<Mapping table="ticket">
<Map column="ticketid"/>
<Map column="eventid"/>
<Map column="status"/>
<Map column="orderid" property="orderid"/>
+ <Map column="pricecategoryid"/>
+ <Map property="pricecategory">
+ <Call lang="php" method="WOPriceCategory::fromTablepricecategory(WTpricecategory::getFromDB($table->pricecategoryid))"/>
+ </Map>
</Mapping>
</Class>
<Var name="order" type="Order">the order that ownes the changed ticket, in case this is called from the order window</Var>
</Output>
</Transaction>
+ <Transaction name="ChangeTicketPriceCategory">
+ <Privilege name="ChangeUsedTicket">users with this privilege can change the price of used tickets - usually a ticket has to be changed before it is used</Privilege>
+ <Privilege name="ChangePastTicket">users with this privilege can change the price for tickets that are for past events</Privilege>
+ <Input>
+ <Var name="barcode" type="astring"/>
+ <Var name="pricecategoryid" type="int"/>
+ </Input>
+ <Call lang="php" method="WOOrder::changeTicketPriceCategory($this);"/>
+ <Output>
+ <Var name="order" type="Order">the order that ownes the changed ticket, in case this is called from the order window</Var>
+ </Output>
+ </Transaction>
<Transaction name="GetAllShipping" updating="no">
<Input/>
$trans->setorder(WOOrder::fromTableorder($ord));
}
+ /**called from the two functions below - checks whether the ticket can be changed*/
+ static protected function changeTicketPriceCheckTicket($trans,$tick,$changeused)
+ {
+ if($tick===false){
+ $trans->abortWithError(tr("Invalid ticket ID."));
+ return false;
+ }
+ $ok = (($tick->status & WTticket::MaskChangeable) ||
+ ($tick->status==WTticket::Used && $trans->havePrivilege($changeused)));
+ if(!$ok){
+ $trans->abortWithError(tr("The ticket cannot be changed anymore or you do not have the privilege."));
+ return false;
+ }
+ return true;
+ }
+ /**called from the two functions below - checks whether the ticket can be changed*/
+ static protected function changeTicketPriceCheckEvent($trans,$event,$changepast)
+ {
+ if($event===false){
+ $trans->abortWithError(tr("Internal error: ticket for unknown event."));
+ return false;
+ }
+ if($event->starttime < time() && !$trans->havePrivilege($changepast)){
+ $trans->abortWithError(tr("The ticket is for an event in the past and you do not have the privilege to change it."));
+ return false;
+ }
+ return true;
+ }
+
/**called from the ChangeTicketPrice transaction*/
static public function changeTicketPrice($trans)
{
//get ticket
$tick=WTticket::getFromDB($trans->getbarcode());
+ //verify ticket
+ if(!self::changeTicketPriceCheckTicket($trans,$tick,WTrChangeTicketPrice::Priv_ChangeUsedTicket))return;
+ $event=WTevent::getFromDB($tick->eventid);
+ if(!self::changeTicketPriceCheckEvent($trans,$event,WTrChangeTicketPrice::Priv_ChangePastTicket))return;
+ //change ticket
+ $tick->price=$trans->getprice();
+ $tick->update();
+ //return order
+ $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($tick->orderid)));
+ }
+ /**called from the ChangeTicketPriceCategory transaction*/
+ static public function changeTicketPriceCategory($trans)
+ {
+ //get ticket
+ $tick=WTticket::getFromDB($trans->getbarcode());
if($tick===false){
$trans->abortWithError(tr("Invalid ticket ID."));
return;
}
//verify ticket
- $ok = (($tick->status & WTticket::MaskChangeable) ||
- ($tick->status==WTticket::Used && $trans->havePrivilege(WTrChangeTicketPrice::Priv_ChangeUsedTicket)));
- if(!$ok){
- $trans->abortWithError(tr("The ticket cannot be changed anymore or you do not have the privilege."));
+ $tick=WTticket::getFromDB($trans->getbarcode());
+ if(!self::changeTicketPriceCheckTicket($trans,$tick,WTrChangeTicketPriceCategory::Priv_ChangeUsedTicket))return;
+ $event=WTevent::getFromDB($tick->eventid);
+ if(!self::changeTicketPriceCheckEvent($trans,$event,WTrChangeTicketPriceCategory::Priv_ChangePastTicket))return;
+ //get category
+ $cat=WTpricecategory::getFromDB($trans->getpricecategoryid());
+ if($cat===false){
+ $trans->abortWithError(tr("Invalid price category."));
return;
}
- $event=WTevent::getFromDB($tick->eventid);
- if($event===false){
- $trans->abortWithError(tr("Internal error: ticket for unknown event."));
+ $prc=WTeventprice::getFromDB($event->eventid,$cat->pricecategoryid);
+ if($prc===false){
+ $trans->abortWithError(tr("Category is not valid for this event."));
return;
}
- if($event->starttime < time() && !$trans->havePrivilege(WTrChangeTicketPrice::Priv_ChangePastTicket)){
- $trans->abortWithError(tr("The ticket is for an event in the past and you do not have the privilege to change it."));
+ //verify category flags
+ global $session;
+ if(!$session->checkFlags($prc->flags)){
+ $trans->abortWithError(tr("You do not have access to this category on this event."));
return;
}
//change ticket
- $tick->price=$trans->getprice();
+ $tick->pricecategoryid=$prc->pricecategoryid;
+ $tick->price=$prc->price;
$tick->update();
//return order
$trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($tick->orderid)));