From: konrad Date: Sun, 16 May 2010 10:53:20 +0000 (+0000) Subject: show price category in order win X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=22656f46031a9fa0b79fe991e04d66604a6e0d74;p=konrad%2Fsmoke.git show price category in order win implement change ticket price category transaction add some sanity checks git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@459 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/dialogs/eventedit.cpp b/src/dialogs/eventedit.cpp index f0f3cd8..a325345 100644 --- a/src/dialogs/eventedit.cpp +++ b/src/dialogs/eventedit.cpp @@ -265,8 +265,14 @@ void MEventEditor::addPrice() 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;iaddAction(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())) @@ -214,7 +216,7 @@ void MOrderWindow::updateData() 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;jselectionModel()->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 + QListtickets=m_order.tickets(); + MOTicket tick; + for(int i=0;i 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;iaddItem(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 diff --git a/src/dialogs/orderwin.h b/src/dialogs/orderwin.h index 8d40e82..a846756 100644 --- a/src/dialogs/orderwin.h +++ b/src/dialogs/orderwin.h @@ -70,6 +70,8 @@ class MOrderWindow:public QMainWindow /**change a ticket/voucher price*/ void changeItem(); + /**change a ticket price category*/ + void changeItemCat(); /**return a ticket/voucher*/ void itemReturn(); diff --git a/src/wext/MOTicket.cpp b/src/wext/MOTicket.cpp index 990d322..c3e4bf1 100644 --- a/src/wext/MOTicket.cpp +++ b/src/wext/MOTicket.cpp @@ -27,3 +27,12 @@ MOEvent MOTicket::event()const //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(); +} diff --git a/src/wext/MOTicket.h b/src/wext/MOTicket.h index 0332fab..2136d76 100644 --- a/src/wext/MOTicket.h +++ b/src/wext/MOTicket.h @@ -30,6 +30,11 @@ class MOTicket:public MOTicketAbstract /**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: diff --git a/wob/order.wolf b/wob/order.wolf index fae345c..05ee7f2 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -175,6 +175,8 @@ + + @@ -182,6 +184,10 @@ + + + + @@ -604,6 +610,18 @@ the order that ownes the changed ticket, in case this is called from the order window + + users with this privilege can change the price of used tickets - usually a ticket has to be changed before it is used + users with this privilege can change the price for tickets that are for past events + + + + + + + the order that ownes the changed ticket, in case this is called from the order window + + diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 4ee24d1..0ec14c5 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -534,33 +534,84 @@ class WOOrder extends WOOrderAbstract $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)));